nginx負載均衡配置正確但是訪問不了

今天在使用nginx配置負載均衡的時候出現了一個很奇怪的現象,配置文件絕對正確的情況下就是訪問不了

	upstream tomcatserver {
		server localhost:9090 weight=3; 
		server localhost:8080 weight=1;
	}
	
    server {
        listen   80;
        server_name  localhost;
        location / {
            proxy_pass  http://tomcatserver;
        }
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #location / {
			#root html;
            #index index.html index.htm; 
        #}

兩個localhost路徑單獨訪問都沒有問題,但是用nginx轉發就不行了,但是nginx單獨用,走靜態資源又是可以的,在網上搜了也有很多小夥伴說是遇到了這種情況,在server配置裏面加一行host代理就行了,如下

	upstream tomcatserver {
		server localhost:9090 weight=3; 
		server localhost:8080 weight=1;
	}
	
    server {
        listen   80;
        server_name  localhost;
        location / {
            proxy_pass  http://tomcatserver;		
            proxy_set_header Host $host;		#加這行代理
        }

看網友們的反饋好像這麼加對某些網友是有效的,但是我也這麼加了就是不行,後面電腦和服務都重啓了還是解決不了,然後就想着是不是端口的問題,就嘗試將端口換了一個,果不其然居然就可以了,如下

	upstream tomcatserver {
		server localhost:9090 weight=3; 
		server localhost:8080 weight=1;
	}
	
    server {
        listen   8000;			# 把這個端口換一下就可以了
        server_name  localhost;
        location / {
            proxy_pass  http://tomcatserver;		
        }

但是很奇怪爲什麼作爲靜態資源服務器訪問的時候也是80端口就沒問題,這個就搞不懂了,找了資料也沒有結果,期待大神幫忙解答

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