1.在CentOS系統上安裝Nginx
在 CentOS6 版本的 EPEL 源中,已經加入了 nginx 的 rpm 包,不過此 RPM 包版本較低。如果需要更新版本,可以使用官方制作的 rpm 包,或者使用源碼包編譯安裝。
還可以使用一些二次開發功能增強的 nginx 版本,例如淘寶的 Tengine 和 OpenResty 都是不錯的選擇。
1.1 常用編譯參數
--prefix=PATH:指定 nginx 的安裝目錄
--conf-path=PATH:指定 nginx.conf 配置文件路徑
--user=NAME:nginx 工作進程的用戶
--with-pcre:開啟 PCRE 正則表達式的支持
--with-http_ssl_module:啟動 SSL 的支持
--with-http_stub_status_module:用于監控 Nginx 的狀態
--with-http-realip_module:允許改變客戶端請求頭中客戶端 IP 地址
--with-file-aio:啟用 File AIO
--add-module=PATH:添加第三方外部模塊
這里提供一個完整的編譯方案:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
--prefix=/usr/local/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/var/tmp/nginx/client_body \ --http-proxy-temp-path=/var/tmp/nginx/proxy \ --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/lock/nginx \ --user=nginx \ --group=nginx \ --with-file-aio \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_sub_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-pcre |
1.2 nginx 的啟動和關閉
啟動 nginx:
1
|
# nginx -c /etc/nginx/nginx.conf |
關閉 nginx
1
|
# nginx -s stop |
重讀配置文件
1
2
|
# nginx -s reload # pkill -HUP nginx |
重新打開日志文件
1
2
|
# nginx -s reopen # pkill -USR1 nginx |
還可以下載 nginx RPM 包中的 /etc/init.d/nginx 文件,修改路徑后即可使用:
# service nginx {start|stop|status|restart|reload|configtest|}
2.在Windows系統上安裝Nginx
首先去官網下載 nginx1.0.11的Windows版本,官網下載:http://nginx.org/download/nginx-1.0.11.zip
下載到軟件包后,解壓 nginx-nginx1.0.11.zip 包到你喜歡的根目錄,并將目錄名改為nginx。
然后,執行下列操作:
1
2
3
|
cd nginx start nginx |
1
2
3
|
nginx -s stop // 停止nginx nginx -s reload // 重新加載配置文件 nginx -s quit // 退出nginx |