Nginx - Windows下Nginx初入門

來源:互聯網
上載者:User

標籤:span   download   分享   tcp   blank   詳解   home   copy   include   

公司剛使用nginx,預先學習下。鑒於機器沒有Linux環境,在Windows熟悉下。

 

下載

1):

  http://nginx.org

 

目前(2017-05-30),nginx的穩定版本是,在官網下載先,12.0

 

2017-04-25

nginx-1.13.0 mainline version has been released.

2017-04-12

nginx-1.12.0 stable version has been released, incorporating new features and bug fixes from the 1.11.x mainline branch - including variables support and other improvements in the stream module, HTTP/2 fixes, support for multiple SSL certificates of different types, improved dynamic modules support, and more.

 

這是一個zip檔案,解壓後即可使用(我是放在d:\)

 

啟動

綠色檔案,無須安裝,直接即可啟動。

據我所知,3種啟動途徑,其實都類似:

一、雙擊nginx.exe表徵圖,可見黑視窗一閃而過,啟動完畢。

二、命令列到nginx目錄,輸入nginx啟動。(注,此方式命令列視窗無任何提示,且被鎖定)

三、命令列到nginx目錄,輸入start nginx啟動,此方式不鎖定

 

啟動後,預設情況下(無修改配置),可見到有兩個nginx的進程,1個是master process,1個是worker processes。

如果你在配置中配置2個worker_processes,進程中就可以看到1個是master process,2個是worker processes。

測試

預設nginx部署了些靜態內容,我們可通過它測試nginx是否在工作。

預設的設定檔(NGINX_HOME/conf/nginx.conf)如下:

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘    #                  ‘$status $body_bytes_sent "$http_referer" ‘    #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {        listen       80;        server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            root   html;            index  index.html index.htm;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #location ~ \.php$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}        # deny access to .htaccess files, if Apache‘s document root        # concurs with nginx‘s one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #    #server {    #    listen       443 ssl;    #    server_name  localhost;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_cache    shared:SSL:1m;    #    ssl_session_timeout  5m;    #    ssl_ciphers  HIGH:!aNULL:!MD5;    #    ssl_prefer_server_ciphers  on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}

 

通過觀察設定檔的非注釋項(參考Nginx設定檔nginx.conf中文詳解),大概可知:

1、啟動了1個worker processes

2、worker_connections,最大並發數為1024

3、include mime.types,引入mime.types檔案所聲明的副檔名與檔案類型映射

4、application/octet-stream,預設使用application/octet-stream

5、sendfile,開啟高效檔案傳輸模式

6、監聽本機“localhost”的80連接埠

7、映射目錄為“目前的目錄的html目錄”

8、出現500、502、503、504錯誤,則映射到50x.html

 

瀏覽地址http://localhost,即可訪問其預設頁面,即映射到NGINX_HOME/html/index.html

其他靜態內容,如html、圖片,可自行添加測試。

日誌

日誌預設位於NGINX_HOME/logs/,可見:

1、access.log,訪問日誌

2、error.log,異常日誌

3、nginx.pid,進程(僅在啟動nginx後才有此日誌)

 

 

轉載:http://www.cnblogs.com/nick-huang/p/4638398.html

 

Nginx - Windows下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.