yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel
mkdir -p /home/dm/tools
1 wget http://nginx.org/download/nginx-1.8.1.tar.gz 2 ls -l 3 tar xf nginx-1.8.1.tar.gz 4 cd nginx-1.8.1/
建立www用戶html
useradd www -s /sbin/nologin -M
1 ./configure --user=www --group=www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module 2 make && make install
安裝時指定版本號路徑是爲了便於查看區分當前使用的nginx版本,也方便之後升級。nginx
當nginx軟件升級編譯成帶新版本號的版本後,刪除原來的軟鏈接,再從新創建新的到/application/nginx/ 的軟鏈接就好。c++
ln -s /application/nginx-1.8.1 /application/nginx
1 root@nginx nginx-1.8.1]# ll /application/|grep nginx 2 lrwxrwxrwx 1 root root 24 8月 19 19:06 nginx -> /application/nginx-1.8.1 3 drwxr-xr-x 11 root root 151 8月 19 19:06 nginx-1.8.1
4 [root@nginx nginx-1.8.1]# ls -l /application/nginx 5 lrwxrwxrwx 1 root root 24 8月 19 19:06 /application//nginx -> /application/nginx-1.8.1 6 [root@nginx nginx-1.8.1]#
1 檢查配置文件語法: 2 /application/nginx/sbin/nginx -t 3 4 啓動nginx: 5 /application/nginx/sbin/nginx
1 [root@nginx nginx-1.8.1]# lsof -i :80 2 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 3 nginx 3663 root 6u IPv4 23418 0t0 TCP *:http (LISTEN) 4 nginx 3665 www 6u IPv4 23418 0t0 TCP *:http (LISTEN) 5 6 [root@nginx nginx-1.8.1]# netstat -lnt|grep 80 7 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
centos6開啓方法: /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/init.d/iptables save service iptables restart centos7開啓方法: firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload
1 [root@nginx nginx-1.8.1]# curl -I 192.168.200.102 2 HTTP/1.1 200 OK 3 Server: nginx/1.8.1 4 Date: Sun, 19 Aug 2018 12:20:40 GMT 5 Content-Type: text/html 6 Content-Length: 612 7 Last-Modified: Sun, 19 Aug 2018 11:06:05 GMT 8 Connection: keep-alive 9 ETag: "5b794f1d-264" 10 Accept-Ranges: bytes
一、在編譯安裝nginx時,能夠使用./configure --help 查看相關參數幫助,下面是編譯時指定的參數及簡單說明:centos
1 --prefix=PATH set installation prefix #設置安裝路徑 2 --user=USER set non-privileged user for #設置用戶權限 3 --group=GROUP set non-privileged group for #進程用戶組權限 4 --with-http_stub_status_module enable ngx_http_stub_status_module #激活狀態信息 5 --with-http_ssl_module enable ngx_http_ssl_module #激活ssl功能
二、nginx啓動命令說明:app
1 /application/nginx/sbin/nginx -h 2 3 -V 顯示版本信息和配置選項並退出; 4 -t 檢測nginx配置文件是否正確; 5 -s 後面能夠跟stop, quit, reopen, reload,用來中止和重啓nginx服務;