1. Install tools and libraries
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2. Directory Structure
Source directory: /home/werben/pkgsrc/nginx
Installation directory: /home/werben/application/nginx
3. Download decompression source code
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. Map 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. Auto start after 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
systemctl daemon-reload
# Start nginx service
systemctl start nginx.service
# Stop nginx service
systemctl stop nginx.service
# Set up auto start
systemctl enable nginx.service
# Stop auto start
systemctl disable nginx.service
# View the current status of the service
systemctl status nginx.service
# Restart service
systemctl restart nginx.service
# View all started services
systemctl list-units --type=service
10. Problems and solutions
# in case`systemctl start nginx.service`The prompt is as follows
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe"for details.
# carried out
systemctl status nginx.service
# If the following error occurs
Process: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 see the following message
If you believe that systemd should be allowed execute access on the>
Then you should report thisas 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 easy to maintain.
The Nginx server block file must end with .conf and be stored in the /etc/nginx/conf.d directory. You can have as many server blocks as you need.
It is a good practice to follow standard naming conventions. For example, if the domain name is mydomain.com, the configuration file should be named mydomain.com.conf
If you use repeatable configuration segments in the domain server block, it is best to reconstruct these segments 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 for each server module.
You can set the root directory of the domain document to any location 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
to sum up
The above is the centos8 custom directory introduced by the editor to install nginx. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time. Thank you very much for your support to the ZaLou.Cn website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!
Recommended Posts