Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
645 views
in Technique[技术] by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...