捣鼓了半天,终于弄好了Nginx的反向代理并替换原来的域名。做个小小的记录,以后能更进一步地学习。
首先,为了能替换url,编译Nginx时需要加上with-http_sub_module模块。如果用的是军哥的lnmp,可以尝试使用军哥的nginx升级脚本(这里),在脚本中的约78行加入 --with-http_sub_module参数。
然后,就是编辑nginx的conf文件了,nginx真是方便啊:
location / {
sub_filter neolee.com f.neobbs.com; #f.neobbs.com是反向的域名,这里就是为了替换原域名
sub_filter_once off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http://neolee.com;
proxy_set_header Host neolee.com;
proxy_pass http://106.187.39.201; #被代理网站的IP地址
proxy_set_header Accept-Encoding "";
}
试试看吧,目前http://f.neobbs.com 就能反代老N的博客啦。
另外--with-http_sub_module模块只支持一条记录的替换,如果需要替换多出,请研究下substitutions4nginx这个第三方模块。
WordPress里登录时会失败,如果增加proxy_redirect off;一行会跳转到原来的站。
[Reply]
老N Reply:
January 2nd, 2012 at 12:58 pm
貌似是的,有什么解决办法么?
[Reply]
在脚本中的约78行加入 –with-http_sub_module参数。
___________
上面的如何实现啊。。如何编译参数。新手,不懂
[Reply]
老N Reply:
January 3rd, 2012 at 12:14 pm
你打开那个脚本就能看到了。就是./configure 后面多个参数吧。
[Reply]