Centos Linux server installed nginx

1. Before installing nginx, we must first make sure that the system has g++, gcc, openssl-devel, pcre-devel and zlib-devel software installed, which can be detected by the command shown in the figure, if we can install us You can uninstall as shown in Figure 2:

yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
 
## If it is installed, remove it
yum remove nginx

2. Download and install the software package

cd /usr/local/

wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz
cd nginx
-1.16.0
.
/configure --prefix=/usr/local/nginx < /span>--pid-path=/var/temp/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp- path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi- temp-path=/var/temp/nginx/scgi
make
make < span style="color: #0000ff;">install

Remember, pid-path cannot be set to /var/run/nginx/nginx.pid. Because every time CentOS restarts, it will delete the self-built directories and files in the /var/run directory, causing nginx to fail to start automatically

After make and make install
Enter /usr/local/nginx Check whether the file exists in the conf, sbin, html folder, if it exists, the installation is successful

3. Add the user to execute the file
ln -s /usr/local/nginx/sbin/nginx /usr /local/bin/nginx

4. Run nginx to execute

 Run curl localhost for test startup

  Share picture

   or access ip from an external browser

  share picture

  

If the browser cannot access, open the firewall or open the port.
Turn off the firewall, systemctl stop firewalld.service
Open the port, firewall-cmd --zone=public --add-port=80/tcp --permanent, firewall-cmd --reload

5. Common commands

Linux nginx operation command: (Assuming that /local/usr/nginx is your nginx installation path, the nginx command has been added to the user executable program above, if not executed, please use /usr/local/nginx /sbin/nginx)
start up:
Method 1: nginx
Method 2: nginx -c /usr/local/nginx/conf/nginx.conf
Reload
nginx -s reload: Reloading takes effect after modifying the configuration
nginx -s reopen: reopen the log file
Detect
nginx -t -c /usr/local/nginx/conf/nginx.conf test whether the nginx configuration file is correct
nginx -t does not specify a configuration file to check whether the configuration file is correct
stop
nginx -s stop: quickly stop nginx
nginx -s quit: complete and orderly stop nginx
Other stopping methods need to check the main process number of nginx, query method ps -ef | grep nginx Find the master process in the process list, and its number is the master process number.

  Share a picture

Stop Nginx calmly:
kill -QUIT main process number
Example: kill -QUIT 16391

Stop Nginx quickly:
kill -TERM main process number

Forcibly stop Nginx:
kill -9 main process number

   In addition, if the pid file storage path is configured in nginx.conf, the file stores the Nginx main process number. If not specified, it will be placed in the nginx logs directory. With the pid file, we don’t need to query the main process number of Nginx first, but send a signal directly to Nginx. The command is as follows:

kill -signal type'/usr/local/nginx/logs/nginx.pid'

6. Auto start after booting

1 vi /etc/rc.local

2 Add in the last line
3 /usr/local/nginx/sbin/nginx

reboot to restart the computer< /p>

yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
 
## If it is installed, remove it
yum remove nginx

cd /usr/local/

wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz
cd nginx
-1.16.0
.
/configure --prefix=/usr/local/nginx < /span>--pid-path=/var/temp/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp- path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi- temp-path=/var/temp/nginx/scgi
make
make < span style="color: #0000ff;">install

If the browser cannot be accessed, open the firewall or open the port.
Turn off the firewall, systemctl stop firewalld.service
Open the port, firewall-cmd --zone=public --add-port=80/tcp --permanent, firewall-cmd --reload

If the browser cannot be accessed, open the firewall or open the port.
Turn off the firewall, systemctl stop firewalld.service
Open the port, firewall-cmd --zone=public --add-port=80/tcp --permanent, firewall-cmd --reload

linux nginx operation command: (assuming /local/usr/nginx For your nginx installation path, the nginx command has been added to the user executable program above. If it is not executed, please use /usr/local/nginx/sbin/nginx)
start up:
Method 1: nginx
Method 2: nginx -c /usr/local/nginx/conf/nginx.conf
Reload
nginx -s reload: Reloading takes effect after modifying the configuration
nginx -s reopen: reopen the log file
Detect
nginx -t -c /usr/local/nginx/conf/nginx.conf test whether the nginx configuration file is correct
nginx -t does not specify a configuration file to check whether the configuration file is correct
stop
nginx -s stop: quickly stop nginx
nginx -s quit: complete and orderly stop nginx
Other stopping methods need to check the main process number of nginx, query method ps -ef | grep nginx Find the master process in the process list, and its number is the master process number.

Stop Nginx calmly:
kill -QUIT main process number
Example: kill -QUIT 16391

Stop Nginx quickly:
kill -TERM main process number

Forcibly stop Nginx:
kill -9 main process number

kill -signal type'/usr/local/nginx/logs/nginx.pid'

1 vi /etc/rc.local

2 Add in the last line
3 /usr/local/nginx/sbin/nginx

Leave a Comment

Your email address will not be published.