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端口就没问题,这个就搞不懂了,找了资料也没有结果,期待大神帮忙解答

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