This article is for record purposes. Please correct me if there are any errors.
1. Preparation
(1) Prepare Nginx package: nginx-xxx.tar.gz
(2) Unzip to /usr/local/nginx
2. Compile
(1) A C environment is required, if it is missing, you can install gcc to solve it
(2) Compilation parameters (can be changed according to the actual situation), if the following directory does not exist, please create it first
1 ./configure \ 2 --prefix=/usr/local/nginx \ 3 --pid-path=/var/run/nginx/nginx.pid \ 4 --lock-path=/var/lock/nginx.lock \ 5 --error-log-path=/var/log/nginx/error.log \ 6 --http-log-path=/var/log/nginx/access.log \ 7 --with-http_gzip_static_module \ 8 --http-client-body-temp-path=/var/temp/nginx/client \ 9 --http-proxy-temp-path=/var/temp/nginx/proxy \ 10 --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ 11 --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ 12 --http-scgi-temp-path=/var/temp/nginx/scgi
(3) After compiling, execute make&make install to install
3. Configure as system service
Create the nginx.service file in the /usr/lib/systemd/system directory and enter the following:
[Unit] Description=nginx server daemon //service description After=network.target //Start sequence [Service] Type=forking PIDFile=/var/run/nginx/nginx.pid //pid file path ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf //Check the configuration file ExecStart=/usr/local/nginx/sbin/nginx //Define the start command ExecReload=/usr/local/nginx/sbin/nginx -s reload //Define the restart command ExecStop=/usr/local/nginx/sbin/nginx -s stop //Define stop command Restart=on-failure //Failed to restart [Install] WantedBy=mutil-user.target
4. Overload configuration
Execute the following command to reload the configuration
systemctl daemon-reload
Start nginx and set it to start at boot
systemctl start nginx systemctl enable nginx
Check status