我试图将Nginx 1.0.12设置为apache 2.2.15的代理,但遇到了一个奇怪的问题.我连续第三天都无法解决这个问题.我有测试站点c-craft.info并在/ roundcube子目录中安装了roundcube.所以这是问题所在:
如果你试图打开http://c-craft.info/roundcube,你会得到奇怪的重定向回你自己的IP地址.所以似乎Nginx试图从remote_addr下载静态文件.但是如果你要像圆形立方体那样向uri添加尾部斜线/它会起作用.
另一个例子:尝试打开http://www.contra.lv – 您也将重定向到您自己的IP地址,并且Nginx再次尝试从remote_addr下载静态文件.
有趣的是,通过apache连接很好:
c-craft.info:9091/roundcube
contra.lv:9091
我真的需要你的建议如何解决它,因为我被困…这是我当前的配置文件:
Nginx.conf
user Nginx;
worker_processes 2;
pid /var/run/Nginx.pid;
events {
worker_connections 2048;
use epoll;
}
http {
include /etc/Nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/Nginx/access.log;
error_log /var/log/Nginx/error.log;
client_max_body_size 64m;
client_body_buffer_size 256k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_vary on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+RSS text/javascript;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6].(?!.*SV1)";
include /etc/Nginx/conf.d/*.conf;
include /etc/Nginx/sites-enabled/*;
}
启用站点-/默认
server {
listen 80 default;
server_name _;
server_name_in_redirect off;
server_tokens off;
access_log /var/log/Nginx/default.access.log;
error_log /var/log/Nginx/default.error.log;
location / {
proxy_pass http://8*.***.**.**6:9091;
include /etc/Nginx/proxy.conf;
}
}
启用站点-/ C-craft.info.conf
server {
listen 80;
server_name www.c-craft.info c-craft.info;
server_name_in_redirect off;
access_log /var/log/Nginx/c-craft.info_access_log;
error_log /var/log/Nginx/c-craft.info_error_log;
location / {
proxy_pass http://8*.***.**.**6:9091;
include /etc/Nginx/proxy.conf;
}
location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar)${
expires 30d;
root /home/c-craft/public_html;
}
}
启用站点-/ contra.lv.conf
server {
listen 8*.***.**.**6:80;
server_name www.contra.lv contra.lv;
access_log /var/log/Nginx/contra.lv_Nginx_access_log;
error_log /var/log/Nginx/contra.lv_Nginx_error_log;
location / {
proxy_pass http://8*.***.**.**6:9091;
include /etc/Nginx/proxy.conf;
}
location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar)${
expires 30d;
root /home/contra/public_html;
}
}
proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 32 8k;
proxy_busy_buffers_size 64k;
在apache httpd.conf中我有:
Listen 9091
UseCanonicalName Off
如果您有任何建议,请提前感谢您.
您的proxy_pass指令应该都有尾部斜杠,例如,来自您的默认配置(修改);
server {
listen 80 default;
server_name _;
server_name_in_redirect off;
server_tokens off;
access_log /var/log/Nginx/default.access.log;
error_log /var/log/Nginx/default.error.log;
location / {
proxy_pass http://8*.***.**.**6:9091/;
include /etc/Nginx/proxy.conf;
}
}
如果您更新上面的所有proxy_pass语句以包含尾部斜杠,您应该会发现您不再需要请求的URL中的尾部斜杠,因此您不应再看到错误的返回到您自己的IP地址描述.