我们往往会使用nginx+apache来作为服务器环境,nginx使用80端口,Apache使用82端口,那么当我们安装discuz的时候,在加入了nginx映射到Apache端口后,往往discuz的链接地址栏上会出现端口号,如82
那么我们如何解决这个问题呢?
x2寻找文件source/class/class_core.php,寻找:$_G[‘siteport’]
将此行注释即可,或者强制在此文件的头部,加上:$_SERVER[‘HTTP_HOST’]=”www.域名.com”;
到此就可以解决discuz论坛地址栏带端口号的解决方法【nginx+apache反射】,但是x2.5是修改:
source/class/discuz/discuz_application.php
————————–
但是你会发现另外一个问题,就是验证码不能正确显示,解决办法如下:
直接在config/config_global.php下增加$_SERVER[‘HTTP_HOST’]=”www.域名.com”;即可解决所有问题
研究半天实在搞不定,原来还有此绝招~
在配置nginx配置反向代理的时候,也许大家会遇到这样的问题,就是发现目录名称后面不加斜杠的话会自动跳转至原网址
比方说:
我将aaa.com反向到bbb.com的82端口
那么配置代码如下:
server {
listen 80;
server_name aaa.com;
location / {
proxy_pass http://bbb.com:82;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
}
access_log logs/bbb.com.access.log;
}
这样配置确实可以,但是如果你输入aaa.com/123
123是一个目录,而不是输入aaa.com/123/
那么nginx会自动原型输出为:bbb.com:82/123/
这样是很讨厌的不是吗,因为既然是反向代理,怎么可以把被代理的潜在域名显示出来呢?
解决方法如下:
加入:proxy_redirect http://bbb.com:82/ /;
这样可以完整解决关于目录结尾加斜杠和不加斜杠的跳转问题
今天配置nginx反向代理的时候,发现无法加载验证码和安全问答问题
经过研究和谷歌搜索,发现原来discuz会在头部判断用户来源
所以解决办法是在nginx的虚拟主机配置中加入:
proxy_pass_header User-Agent;
proxy_set_header Host $host;
这样才能正确加载discuz中的验证码和安全问题
如果你也遇到了在nginx中无法加载discuz中的验证码,请使用上方同样的方法,我列举一个虚拟主机的配置例子:
server {
listen 80;
server_name bbs.aaa.com;
location / {
proxy_pass http://bbs.aaa.com:82;
proxy_redirect http://bbs.aaa.com:82/ /;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
}
access_log logs/bbs.aaa.com.access.log;
}
由于反锁的备案流程,本人决定采用nginx做反向代理,原理很简单:
在香港购买一台VPS,安装nginx软件+iis软件+apache软件+php软件+mysql软件,作用如下:
1,nginx用来监听80端口,处理所有的http请求
2,iis用来监听81端口,用来处理asp程序
3,apache用来监听82端口,用来处理本地VPS中的php+mysql程序
原理如下,当用户访问指定域名的时候,通过nginx监听域名,可以指定单独到81或者82端口,如此,本地可运行asp程序和php程序,当遇到适当的域名的时候,直接反向到指定另外一台国内服务器上(支持80端口开放,或者没开放80端口的IP)
这个方法真的实在是太棒了,呵呵,有几下优点:
1,可以免备案
2,支持asp+php+asp.net+jsp+access+mysql+sqlserver,全方面反向代理
但是实际运作配置环境中,遇到一个问题,就是目录不带斜杠跳转的问题,那么如何解决?
可以通过nginx中的proxy_redirect解决,如下:
假如你要访问的域名是www.zhanghongliang.com,这个时候请求的过程是:
用户->香港->nginx->国内
那么nginx会自动反向到国内的指定域名,比方说是:www.zhanghongliang.cn,但是如果我输入www.zhanghongliang.com/category/divcss那么会自动跳转到www.zhanghongliang.cn/category/divcss,这样本身不需要暴漏的域名就被暴漏了,解决办法是:
在nginx的server中加入
proxy_redirect http://www.zhanghongliang.com/ /;
以下是来自网络的方法(经过本人nginx windows 1.4.1测试无效):
1,加入:server_name_in_redirect off;(但是nginx自0.9.8开始就默认是off)
2,将server_name localhost;改成server_name $hostname;(测试无效,因为我是多个虚拟主机server,无法使用$hostname)
3,加入配置重写文件:if (!-f $request_filename){ rewrite ^/([^.]+[^/])$ http://$host/$1/ permanent; }(未测试)
用我提供的方法可以完美解决“nginx反向代理目录不带斜杠跳转的问题”;
升华,结束!
nginx发展太快了,已到1.5.1版本了,apache更新太慢了,要跟上啊,要不然你的市场份额真的会被抢完的。
以下是nginx 1.5.1正式版的改版内容
Changes with nginx 1.5.1 04 Jun 2013
*) Feature: the “ssi_last_modified”, “sub_filter_last_modified”, and
“xslt_last_modified” directives.
Thanks to Alexey Kolpakov.
*) Feature: the “http_403” parameter of the “proxy_next_upstream”,
“fastcgi_next_upstream”, “scgi_next_upstream”, and
“uwsgi_next_upstream” directives.
*) Feature: the “allow” and “deny” directives now support unix domain
sockets.
*) Bugfix: nginx could not be built with the ngx_mail_ssl_module, but
without ngx_http_ssl_module; the bug had appeared in 1.3.14.
*) Bugfix: in the “proxy_set_body” directive.
Thanks to Lanshun Zhou.
*) Bugfix: in the “lingering_time” directive.
Thanks to Lanshun Zhou.
*) Bugfix: the “fail_timeout” parameter of the “server” directive in the
“upstream” context might not work if “max_fails” parameter was used;
the bug had appeared in 1.3.0.
*) Bugfix: a segmentation fault might occur in a worker process if the
“ssl_stapling” directive was used.
Thanks to Piotr Sikora.
*) Bugfix: in the mail proxy server.
Thanks to Filipe Da Silva.
*) Bugfix: nginx/Windows might stop accepting connections if several
worker processes were used.
近期评论