windows下nginx的安裝應用

1、nginx安裝

  1. 到nginx官網上下載相應的安裝包,http://nginx.org/en/download.html;
    在這裏插入圖片描述
    下載進行解壓,將解壓後的文件放到自己心儀的目錄下,我的解壓文件放在了d盤根目錄下,如下圖所示:

在這裏插入圖片描述

進入window的cmd窗口,輸入如下圖所示的命令,進入到nginx目錄(D:/nginx-1.8.1),使用“start nginx.exe ”進行nginx的安裝,如下圖所示:
在這裏插入圖片描述
安裝成功後,在“任務管理器”中會看到“nginx.exe”進程,如下圖所示:

在這裏插入圖片描述

在瀏覽器地址欄輸入:127.0.0.1,會看到如下圖所示的nginx歡迎界面
在這裏插入圖片描述
2、nginx的使用
Windows下Nginx的啓動、停止等命令
在Windows下使用Nginx,我們需要掌握一些基本的操作命令,比如:啓動、停止Nginx服務,重新載入Nginx等,下面我就進行一些簡單的介紹。
1、啓動:
C:\server\nginx-1.0.2>start nginx或
C:\server\nginx-1.0.2>nginx.exe

2、停止:
C:\server\nginx-1.0.2>nginx.exe -s stop或
C:\server\nginx-1.0.2>nginx.exe -s quit
注:stop是快速停止nginx,可能並不保存相關信息;quit是完整有序的停止nginx,並保存相關信息。

3、重新載入Nginx:
C:\server\nginx-1.0.2>nginx.exe -s reload
當配置信息修改,需要重新載入這些配置時使用此命令。

4、重新打開日誌文件:
C:\server\nginx-1.0.2>nginx.exe -s reopen

5、查看Nginx版本:
C:\server\nginx-1.0.2>nginx -v

3、windows下nginx訪問web目錄提示403 Forbidden
 在windows下 http服務器nginx時,訪問web目錄提示403 Forbidden,首先需要了解nginx出現403錯誤是什麼意思:

403 Forbidden表示你在請求一個資源文件但是nginx不允許你查看,403 Forbidden 只是一個HTTP狀態碼,像404,200一樣不是技術上的錯誤。

  找到nginx.conf:

將user nobody 改爲user root;重啓ng,仍無效果。

  後發現nginx默認是不支持瀏覽目錄的。

  找到 autoindex  off 更改爲on。 重啓ng,正常訪問。

4、nginx.conf


user  root;
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       8086;
        server_name  localhost;
        root         F:\ShoppingImg;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   F:\ShoppingImg;
            index  index.html index.htm;
	    autoindex on;
        }

        #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;
    #    }
    #}
    
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章