CentOS 8 custom directory installation nginx (tutorial details)

CentOS 8 custom directory installation nginx (tutorial details)

1. Install tools and libraries

# PCRE is a Perl library that includes a Perl-compatible regular expression library. nginx's http module uses pcre to parse regular expressions

# The zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the contents of the http package.

yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

2. Directory Structure

Source code directory: /home/werben/pkgsrc/nginx
Installation directory: /home/werben/application/nginx

3. Download and decompress the source code

# Official website address: https://nginx.org/en/download.html
wget -c https://nginx.org/download/nginx-1.17.5.tar.gz

4. Create user groups and users

groupadd www
useradd -g www www

5. Compile source code

./configure --user=www --group=www --prefix=/home/werben/application/nginx --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre

make && make install

6. Mapping global commands

ln -s /home/werben/application/nginx/sbin/nginx /usr/local/bin/nginx

7. Start, stop, restart

nginx -s stop
nginx -s quit
ngins -s reload

8. Check the correctness of the configuration file nginx.conf

nginx -t

9. Start automatically at boot

vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=nginx
ExecReload=nginx reload
ExecStop=nginx quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
#Reload the daemon process systemctl daemon-reload

#Start nginx service systemctl start nginx.service
#Stop the nginx service systemctl stop nginx.service
#Set the system to start automatically at boot time systemctl enable nginx.service
#Stop booting automatically systemctl disable nginx.service
#View the current status of the service systemctl status nginx.service
#Restart the service systemctl restart nginx.service
#View all started services systemctl list-units --type=service

10. Problems and solutions

#If `systemctl start nginx.service` prompts the following error: Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

#Execute systemctl status nginx.service
#If the following error occursProcess: 35783 ExecStart=...nginx/sbin/nginx(code=exitedstatus=203/EXEC)
  nginx.service: Control process exited, code=exited status=203
  systemd[1]: nginx.service: Failed with result 'exit-code'.
  localhost.localdomain systemd[1]: Failed to start nginx.


journalctl -xe

#If you believe that systemd should be allowed execute access on the>
  Then you should report this as a bug.
  You can generate a local policy module to allow this access.
  Do allow this access for now by executing:
  # ausearch -c '(nginx)' --raw | audit2allow -M my-nginx
  # semodule -X 300 -i my-nginx.pp


#Solution: setenforce 0
vim /etc/selinux/config
SELINUX=disabled

ps: Structure description of Nginx configuration file

All Nginx configuration files are located in the /etc/nginx/ directory.

The main configuration file of Nginx is /etc/nginx/nginx.conf.

Creating a separate configuration file for each domain makes the server easier to maintain.

Nginx server block files must end with .conf and are stored in the /etc/nginx/conf.d directory. You can have as many server blocks as you want.

It is a good practice to follow standard naming conventions. For example, if the domain name is mydomain.com then the configuration file should be named mydomain.com.conf

If you use repeatable configuration sections in your domain server blocks, it is a good idea to refactor these sections into fragments.

Nginx log files (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to have different access and error log files per server module.

You can set the domain document root to anywhere you want. The most common locations for webroot include:

/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
/usr/share/nginx/html

Summarize

The above is what I introduced to you about installing nginx in a custom directory on centos8. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Nginx installation detailed tutorial
  • How to install PHP7.4 and Nginx on Centos
  • Detailed tutorial for installing nginx on centos8 (picture and text)
  • Correct steps to install Nginx in Linux
  • Solve the problem of "Welcome to nginx on Fedora!" after installing nginx on Centos7, and there is no default.conf file in the conf.d directory
  • Centos7.3 How to install and deploy Nginx and configure https
  • How to install nginx under Linux
  • Nginx installation error solution

<<:  In-depth explanation of the locking mechanism in MySQL InnoDB

>>:  Best Practices for Developing Amap Applications with Vue

Recommend

Solution to css3 transform transition jitter problem

transform: scale(); Scaling will cause jitter in ...

Reasons why MySQL kill cannot kill threads

Table of contents background Problem Description ...

How to use the Linux md5sum command

01. Command Overview md5sum - Calculate and verif...

How to install MySQL 5.7.29 with one click using shell script

This article refers to the work of 51CTO blog aut...

Time zone issues with Django deployed in Docker container

Table of contents Time zone configuration in Djan...

How to create a database in navicat 8 for mysql

When developing a website, you often need to use ...

Do you know how to use the flash wmode attribute in web pages?

When doing web development, you may encounter the...

JS removeAttribute() method to delete an attribute of an element

In JavaScript, use the removeAttribute() method o...

Example of how to implement MySQL cascading replication

The so-called cascading replication is that the m...

How to install and configure MySQL and change the root password

1. Installation apt-get install mysql-server requ...

Example of JSON output in HTML format (test interface)

To display the JSON data in a beautiful indented ...

JS realizes special effects of web page navigation bar

This article shares with you a practical web navi...

Vuex modularization and namespaced example demonstration

1. Purpose: Make the code easier to maintain and ...