1. Installation tools and libraries
#PCRE is a Perl library, including a Perl compatible regular expression library. Nginx’s HTTP module uses PCRE to parse regular expressions
#Zlib library provides many ways to compress and decompress. Nginx uses zlib to gzip the content of 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 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. Detection profile nginx.conf Correctness
9. Start up automatically
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 Daemons systemctl daemon-reload #Start nginx service systemctl start nginx.service #Stop nginx service systemctl stop nginx.service #Set boot up systemctl enable nginx.service #Stop and start systemctl disable nginx.service #View current service status systemctl status nginx.service #Restart service systemctl restart nginx.service #View all started services systemctl list-units --type=service
10. Problems and Solutions
#If 'systemctl start' nginx.service `The following is an error Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. #Implementation 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: nginx.service: Failed with result 'exit-code'. localhost.localdomain systemd: Failed to start nginx. journalctl -xe #If you see the following information 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 #Solutions 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 for nginx is / etc / nginx/ nginx.conf 。
Create a separate configuration file for each domain to make 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 want.
It’s a good habit 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 a domain server block, it is best to refactor these segments into fragments.
Nginx log file（ access.log and error.log ）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 of a domain document to any location you want. The most common locations of Webroot include:
/home/<user_name>/<site_name> /var/www/<site_name> /var/www/html/<site_name> /opt/<site_name> /usr/share/nginx/html
The above is a small introduction to the centos8 custom directory installation nginx, I hope to help you, if you have any questions, please leave me a message, Xiaobian will reply you in time. Thank you very much for your support to the developeppaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!