Windows下Nginx初入門

jopen 9年前發布 | 27K 次閱讀 Nginx Web服務器


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

下載

目前(2015-07-11),nginx的穩定版本是1.8.0,在官網下載先, windows版的nginx1.8.0

這是一個zip文件,解壓后即可使用

啟動

綠色文件,無須安裝,直接即可啟動。

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

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

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

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

啟動后,默認情況下(無修改配置),可見到有兩個nginx的進程,一個是master process,一個是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后才有此日志)

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!