首页  >  问答  >  正文

集群 - nginx怎么配置IP和域名都能访问

我用nginx做了个集群,部署在电信云上,外网使用ip访问,192.100.xxx.xxx:8080/jess,还有个域名访问 www.xxx.net/jess 进行访问,域名是局方自己映射的。

自己搞个,用ip访问没有问题,用域名访问的话首页可以打开,登录后请求又都返回ip了,要如何配置才能做到ip访问,返回ip,域名访问返回域名。贴下我的nginx配置

第一次使用nginx 找了些资料都不是想要的,希望能请高手教下,或者哪里有nginx 配置详解好的资料提供下。先谢过了

 #负载均衡配置
     upstream tomcat_server {
          server 192.168.156.1:8090 max_fails=3 weight=1 fail_timeout=60s;
          server 192.168.156.2:8080 max_fails=3 weight=3 fail_timeout=60s;
       }
    server {
        listen 8080;
        server_name  localhost,;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            index    index.jsp;
            proxy_pass  http://tomcat_server;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
过去多啦不再A梦过去多啦不再A梦2713 天前808

全部回复(2)我来回复

  • 迷茫

    迷茫2017-05-16 17:11:10

    如何后端是通过30x跳转的话,可以使用:

    proxy_redirect http://192.100.xxx.xxx/ /;

    来替换响应头中的Location,如果是页面使用javascript跳转的,那可能需要修改后端代码,如果无法修改,可以使用sub_filter之类的nginx替换模块。
    参考https://www.centos.bz/2014/06...

    回复
    0
  • PHP中文网

    PHP中文网2017-05-16 17:11:10

    求答疑,还是没有找到解决方案

    回复
    0
  • 取消回复