内网ip

apache,nginx反向代理出现内网ip解决方法

星期四, 二月 23rd, 2012 | JAVA-and-J2EE, linux | 没有评论

apache中设置如下反向代理后端的tomcat出现
request.getServerName();获取到的主机名称就会是localhost,解决这个

<VirtualHost *:80>
    ServerAdmin service@i5a6.com
    DocumentRoot /usr/local/apache/htdocs
    ServerName i5a6.com
    ServerAlias *.i5a6.com
     DirectoryIndex  index.html  index.html.var  index.jsp
     ProxyPass / http://localhost:8080/
     ProxyPassReverse / http://localhost:8080/
     ErrorLog "logs/hscode-error.log"
     CustomLog "logs/hscode-access.log" common
</VirtualHost>

在httpd.conf 文件中增加:
ProxyPreserveHost On 即可

对应的nginx 也有此问题解决之法:
proxy_set_header Host $host;

upstream mytomcat{
 #server 127.0.0.1:8000 weight=3;
 #server 127.0.0.1:8001;
 #server 127.0.0.1:8002;
 server 127.0.0.1:8080;
 }
 
server
{
listen 80;
server_name i5a6.com *.i5a6.com;
index index.html index.htm ;
root /usr/local/data/htdocs/www;
 
location / {
# proxy_set_header Host %host;
# proxy_set_header X-Forwarded-For $remote_addr;
 proxy_pass http://mytomcat;
proxy_set_header Host $host;
 }

Tags: , , , ,

Search

文章分类

Links

Meta