編譯安裝nginx

安裝nginx依賴包

yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel

創建一個工具目錄來固定存放安裝的各類軟件

mkdir -p /home/dm/tools

進入/home/dm/tools目錄下載並解壓nginx安裝包

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

 編譯安裝nginx

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的安裝路徑經過軟鏈接的方式更改成/application/nginx,方便人員使用。

  安裝時指定版本號路徑是爲了便於查看區分當前使用的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 

查看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 

防火牆開啓80端口

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服務;
相關文章
相關標籤/搜索