0

我有一个 Ubuntu 13.04 虚拟机,带有 nginx 前端服务器和 apache 后端,为 django 项目提供服务。Apache 本身在与 nginx 分开运行时似乎工作正常(反之亦然)。但是看起来当它们一起工作时,请求并没有被 nginx 传递给 Apache。

在浏览器中输入 my_host_name.com 后,我得到 nginx "Welcome ....!" 页面,但它应该是一个 apache 渲染的页面。

UPD:“欢迎...”页面仅在首次加载时出现,在浏览器(chrome)重新启动(缓存?)之后,否则它只返回一个空页面(“此网页不可用...... ... 错误代码:ERR_CONNECTION_RESET ")。从主机操作系统访问 _my_domain_name.com_ 时,我立即收到相同的错误页面。每次配置更改后,我都会重新启动两台服务器(以防万一)。

输入 my_domain_name.com:8000 会返回正确的 apache 响应(不包括静态文件)

经过一天的谷歌搜索仍然找不到问题所在。

我的服务器的设置是:

文件:/etc/nginx/proxy_params

proxy_redirect              off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size        10m;
client_body_buffer_size     128k;
proxy_connect_timeout       90;
proxy_send_timeout          90;
proxy_read_timeout          90;
proxy_buffer_size           4k;
proxy_buffers               4 32k;
proxy_busy_buffers_size     64k;
proxy_temp_file_write_size  64k;

文件:/etc/nginx/sites-available/my_domain_name

server {
    listen 80;
    server_name my_domain_name.com;
    location / {
        access_log /var/log/nginx/localhost.access.log;
        proxy_pass http://127.0.0.1:8000;
        include /etc/nginx/proxy_settings;
    }
    location /static/ {
        root /path/to/my/project/root;
    }
    location /media/{
        root /path/to/my/project/root;
    }
}

文件:/etc/apache2/sites-available/my_domain_name.conf

<VirtualHost *:8000>
    WSGIScriptAlias / /path/to/my/project/root/django.wsgi

    ServerName my_domain_name.com


    <Directory /path/to/my/project/root>
        Order allow,deny
        Allow from all
    </Directory>

    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    RPAFenable On
    RPAFsethostname On
    RPAFproxy_ips  192.168.137.10 127.0.0.1
</VirtualHost>

文件:/etc/apache2/ports.conf

NameVirtualHost *:8000
Listen 8000

文件:/etc/hosts

192.168.137.10 my_domain_name.com
127.0.0.1      my_domain_name.com

谢谢!

4

1 回答 1

0

I was having a similar issue with my Nginx setup with my Apache back end, specifically when Apache was issuing a redirect for:

/some-location => /some-location/

Nginx was running on port 80, and my back end Apache on port 8000. and port 8000 was being passed onto the client in the 301 redirect.

It took a bit of playing, but I was able to get it to work. Here is what I had to do:

location / {
   proxy_pass      http://127.0.0.1:8000;
   proxy_redirect  default;
   proxy_redirect  http://$host:8000/ http:/$host/;
   ... etc ..
}

Both Nginx and Apache virtual servers are using the same hostname (i.e. mydomain.com)

于 2015-04-15T05:04:58.957 回答