在Linux和Windows系統上安裝Nginx伺服器的教程_nginx

來源:互聯網
上載者:User

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 Regex的支援
    --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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.