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:添加第三方外部模塊
這里提供一個完整的編譯方案:
--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:
# nginx -c /etc/nginx/nginx.conf
關閉 nginx
# nginx -s stop
重讀配置文件
# nginx -s reload# pkill -HUP nginx
重新打開日志文件
# 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。
然后,執行下列操作:
cd nginxstart nginx這樣,nginx 服務就啟動了。打開任務管理器,查看 nginx.exe 進程,有二個進程會顯示,占用系統資源,那是相當的少。然后再打開瀏覽器,輸入 http://127.0.0.1/ 就可以看到nginx的歡迎頁面了,非常友好
nginx -s stop // 停止nginxnginx -s reload // 重新加載配置文件nginx -s quit // 退出nginx
新聞熱點
疑難解答