Nginx Windows詳細安裝部署教程


1、下載nginx包

直接去官網下載:http://nginx.org/en/download.html 

2、下載完成后,在指定位置解壓縮,不要直接雙擊nginx.exe。

3、運行cmd,進入解壓的指定目錄下

 

 

 4、啟動nginx服務,啟動命令為:start nginx,啟動時會一閃而過是正常的

 5、查看任務進程是否存在,命令:tasklist /fi "imagename eq nginx.exe"

 

 

 6、進入解壓縮目錄,在conf目錄下找到nginx.conf使用txt文本打開即可,找到server這個節點,進行修改

 

  需修改的下圖四個地方

文件內容如下

#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       8888;//輸入端口號
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   D:/nginx-1.16.1/html/dist; //輸入包的地址
            index  index.html index.htm;
            try_files $uri $uri/ @router;
        }
        location @router{
         #rewrite ^.*/index.html last;
             rewrite ^(.+)$ /index.html last;
         }


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

}

7、修改完成后保存,使用以下命令檢查一下配置文件是否正確,后面是nginx.conf文件的路徑,successful就說明正確了

命令:nginx --/nginx-1.16.1/conf/nginx.conf

 

8、如果程序沒啟動就直接start nginx啟動,如果已經啟動了就使用以下命令重新加載配置文件並重啟

 命令:nginx -reload

9、之后就打開瀏覽器訪問剛才的域名及端口http://localhost:8888,出現歡迎頁就說明部署成功了

 

 10、關閉nginx服務使用以下命令,同樣也是一閃而過是正常的,看一下是否進程已消失即可

快速停止:nginx -s stop

完整有序的關閉:nginx -s quit

11、把安裝包放在D:\nginx-1.16.1\html目錄下,進行解壓

 

 

12、在dos指定路徑下,輸入 命令:nginx -reload,重啟

13、打開瀏覽器訪問http://localhost:8888,就可以訪問自己的項目了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM