Install nginx in centos8 custom directory (detailed tutorial)

1. Install tools and libraries

PCRE is a Perl library, including Perl compatible regular expression library. The http module of nginx 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 directory: /home/werben/pkgsrc/nginx
Installation directory: /home/werben/application/nginx

3. Download decompression 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. 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

Install nginx in centos8 custom directory (detailed tutorial)
How to install php7.3 in centos8 custom directory
vmware install CentOS 7 detailed tutorial
Minimal install JDK 1.8 tutorial in CentOS 7
Centos7.3 install nginx
Centos7 install Nginx
Detailed tutorial on installing MySQL 8 in CentOS 7
Install MySQL5.7 in centos7
Install php in centos
Centos install MYSQL8.X tutorial
Centos install elasticsearch tutorial
Centos7 install kubernetes tutorial
Centos7 install Mysql8 tutorial
Centos7 installation of PHP and Nginx tutorial detailed
Install redis5.0 in CentOS7
Detailed tutorial of installing nginx on centos8 (graphic)
Detailed explanation of CentOS7 network setting tutorial in vmware
CentOs7.3 compile and install Nginx 1.9.9
Linux Centos7 install redis tutorial
Tencent Cloud Centos install nginx
5.1. CentOS@ install JDK1.8 graphic tutorial
CentOS 7 yum install PHP7.3 tutorial
Install Nginx server on CentOS 7
Install Mesos tutorial under CentOS7
Detailed steps to install and configure k8s cluster in centos 7
Install JDK8 in rpm on CentOS7
CentOS 7 install Nginx, PHP, MySQL packages
CentOS 8 installation of MariaDB detailed tutorial
CentOS8.1 build Gitlab server detailed tutorial
Detailed use of nmcli in CentOS8
How to install PHP7.4 in CentOS
CentOS6 minimal installation KVM detailed tutorial
Install MySql with Docker in CentOS7
CentOS8 install jdk8 / java8 tutorial (recommended)
Linux CentOS 7 install JDK detailed steps
CentOS 6.x compile and install Nginx
Install Percona Server database (in CentOS 8)
Install java in yum mode in Centos
How to install Nginx on CentOS 8
CentOS7.3 install iptables and detailed use
Centos8 installation diagram (super detailed tutorial)
CentOS6 mininal install CouchDB2 detailed version
How to install HDP2.6 in Centos7.2
Install Centos7 operating system in Docker
Centos install php73 fast cgi + nginx
Install and configure FreeIPA in Centos7
How to install Android SDK in centos7
Centos install sshfs to achieve mount directory
Deploy Docker and configure Nginx in CentOS
1.5 Install Centos7
Compile and install nodejs and yum in Centos8
Centos8 use yum to install rabbitmq tutorial
Install Docker CE in yum under CentOS 7
Windows10 install ubuntu20.04 dual system detailed graphic tutorial
The most complete centos installation tutorial in history
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
CentOS8 detailed tutorial for configuring local yum source
Linux (CentOS7) using RPM to install mysql 8.0.11 tutorial
Build LEMP (Linux+Nginx+MySQL+PHP) environment under CentOS 8.1 (detailed tutorial)
CentOS7 Docker Nginx deployment and operation detailed explanation
Centos6 install Python2.7.13