WIN10下安裝和使用Nginx

  1. 下載WINDOWS版本 -- http://nginx.org/en/download.html 下載的是ZIP包,解壓到喜歡的目錄。html

  2. 修改\conf\nginx.conf中的監聽端口(listen),改爲喜歡的端口,好比8090nginx

  3. 進入剛纔的目錄,使用命令 start nginx 啓動nginx服務,訪問 http://localhost:8090 進行測試api

#啓動nginx服務
start nginx
  1. 關閉或重啓nginx
#不保存退出 
nginx -s stop

#保存退出 
nginx -s quit

#重啓 
nginx -s reload
  1. 反向代理
#配置文件中,第一個server{...}節後,添加一個server節。
	#示例訪問http://127.0.0.1:8088時,會跳轉到  http://localhost/test1
    server{
        listen 8088;
        server_name 127.0.0.1;
        location / {
               proxy_pass http://localhost/test1;
        }
    }
  1. 負載均衡
upstream shareapis {
        server 內網IP1:8011 weight=10;
        server 內網IP2:8011 weight=10;
    }

server {
        listen       80;
        server_name  外網IP;
        location / {
            proxy_pass   http:// shareapis;
        }
  
    }
  1. 虛擬目錄(alias)
location  / {
            root   html; 
            index  index.html index.htm;
        }


        location  /dist/ {
            #root   D:/Services/nginx/html;
            alias D:/Apps/element-starter/dist/;
            index  index.html index.htm;
        }

發現這裏講的很細:http://jspang.com/post/nginx.htmlbash

相關文章
相關標籤/搜索