1. Goal
Compile and install nginx on centos7
2. Environment
centos7.6,nginx1.17.7
Three, detailed steps
1. Pre-install pre-requisite components
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2. Download nginx
The official source code download page http://nginx.org/en/download.html
can also download the specified source package according to your own situation (you only need to change the version number in the URL)
http://nginx.org/download /nginx-1.16.1.tar.gz
http://nginx.org/download/nginx-1.17.7.tar.gz
wget -P /usr/local/src/ http://nginx.org/download/nginx-1.17.7.tar.gz
cd /usr/local/src
tar zxvf nginx-1.17.7.tar.gz
cd /usr/local/src/nginx-1.17.7
3. Add the account and group used to start nginx
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
4. Compile the nginx source code (the command --with is used here to install only part of the nginx package, in fact, you need to search for relevant software packages to install to meet your business needs)
Note:
--prefix=/usr/local/ nginx specifies the installation path, you can modify
user=nginx to specify that the user who starts nginx is called nginx
group=nginx to specify the user group that starts nginx is called nginx
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-debug \
--with-stream
5. Start installing nginx
make && make install
6. Check whether nginx is installed successfully (check the version number)
cd /usr/local/nginx/sbin
./nginx -V
7. Modify the main nginx configuration file to make nginx the startup user of the nginx program.
If you modify the nginx installation path, the path in the second half of this command also needs to be modified to your nginx installation path
sed -i 's/#user nobody;/user nginx nginx;/' /usr/local/nginx/conf/nginx.conf
8. Add nginx to the system service
cat > /lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
9. Check whether the process has nginx service
ps -ef |grep nginx
kill all nginx services
pkill nginx
10. Start nginx and set nginx to start automatically after booting
systemctl restart nginx
systemctl enable nginx
-----------END------------------------------------
Double click 666