nginx 配置多服務器代理

找到 nginx > conf目錄中nginx.conf javascript

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

    # access_log  /var/log/nginx/access.log  main;

    # 負載均衡演示之 upstream 參考 https://blog.csdn.net/caijunsen/article/details/83002219
    upstream psjcserver {
	    server 192.168.20.81:8091;
	    #server 172.18.253.44:8083;
    }

    # 讀取conf.d目錄的conf配置
    include "E:/nginx-1.17.2/conf/conf.d/*.conf";


}

  

在nginx > conf目錄中建立一個conf.d目錄 (conf.d用於存放多個服務器配置)html

目錄中建立了一個admin.conf,用於在下圖中被識別*confjava

  

 

生產的admin.conf代碼,管理admin服務器nginx

server {
	listen       80;
	server_name  127.0.0.1;

	location / {
		root   "E:/admin";
		index  index.html index.htm;
	}

	location /admin/ {
	    # rewrite 匹配 localhost/admin 轉成 http://psjcserver
	    rewrite  ^.+admin/?(.*)$ /$1 break;
	    # proxy_pass 設置代理藉口
		proxy_pass http://psjcserver;
		# 若是後端真是的服務器設置有相似防盜鏈或者根據http請求頭中的host字段來進行路由或判斷功能的話,若是反向代理層的nginx不重寫請求頭中的host字段,將會致使請求失敗,報400錯誤
		proxy_set_header Host $http_host;
		$autoindex  on;
	}

	location /favicon.ico {
		root	html;
	}

	error_page   500 502 503 504  /50x.html;
	location = /50x.html {
		root   html;
	}
}
相關文章
相關標籤/搜索