CentOS Linux server installed Nginx

1. Before mounting Nginx, we must first make sure that the system is installed g ++, gcc, openssl-devel, pcre-devel and zlib-devel software, it can be detected by the command shown in FIG, if the installation shown in Figure 2 we can uninstall:

GCC-C ++ the install yum 
yum the install zlib zlib -Y-devel OpenSSL OpenSSL - devel PCRE PCRE devel- 
 
## if installed, then remove off 
yum remove nginx

2. Download and install the 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 \
--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  install

Remember, pid-path can not be set /var/run/nginx/nginx.pid. Because CentOS after each restart, will self delete files and directories / var / run directory, leading to failure from the start nginx

After the make and make install
into the / usr / local / nginx view the file exists conf, sbin, html folder, if there is a successful installation

3. Add into the user can perform file
ln -s / usr / local / nginx / sbin / nginx / usr / local / bin / nginx

4. Run nginx to perform

 Start test run curl localhost

  

  Or visit the ip from an external browser

  

  

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

5. Common Commands

linux nginx操作命令:(假设 /local/usr/nginx 为你nginx的安装路径,上方已经将nginx命令添加进用户可执行程序,如没有执行请使用/usr/local/nginx/sbin/nginx)
启动:
方式一 : nginx
方式二: nginx -c /usr/local/nginx/conf/nginx.conf 
重新加载
nginx -s reload :修改配置后重新加载生效
nginx -s reopen :重新打开日志文件
检测
nginx -t -c /usr/local/nginx/conf/nginx.conf 测试nginx配置文件是否正确
nginx -t 不指定配置文件检测配置文件是否正确
停止
nginx -s stop :快速停止nginx
nginx -s quit :完整有序的停止nginx
其他的停止方式需要查看nginx的主进程号,查询方式 ps -ef | grep nginx 在进程列表里 面找master进程,它的编号就是主进程号了。

  

从容停止Nginx:
kill -QUIT 主进程号  
例如:kill -QUIT 16391

快速停止Nginx:
kill -TERM 主进程号  

强制停止Nginx:
kill -9 主进程号 

  另外, 若在nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在nginx的logs目录下。有了pid文 件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:

kill -信号类型'/usr/local/nginx/logs/nginx.pid'

6.开机自启动

1 vi /etc/rc.local
2 在最后一行添加
3 /usr/local/nginx/sbin/nginx

reboot 重启计算机

 

Guess you like

Origin www.cnblogs.com/houss/p/11282471.html