Centos8 custom directory installation nginx (tutorial details)


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

nginx  -t

9. Start up automatically

vim /lib/systemd/system/nginx.service

ExecReload=nginx reload
ExecStop=nginx quit

#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.

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 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

setenforce 0
vim /etc/selinux/config

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:



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!

Recommended Today

Comparison and analysis of Py = > redis and python operation redis syntax

preface R: For redis cli P: Redis for Python get ready pip install redis pool = redis.ConnectionPool(host=’′, port=6379, db=1) redis = redis.Redis(connection_pool=pool) Redis. All commands I have omitted all the following commands. If there are conflicts with Python built-in functions, I will add redis Global command Dbsize (number of returned keys) R: dbsize P: print(redis.dbsize()) […]