Nginx 代理不工作

Nginx 代理不工作

我正在尝试将所有流量从 www.impactteachers.com/teach 重定向到 application.impactteachers/teach。

这样,我们的申请表也可以从以下网址访问:www.impactteachers.com/teach/

在我们当前的 Apache 服务器上,这条规则可以很好地运行:

ProxyRequests Off
ProxyPreserveHost On

    <Proxy http://application.impactteachers.com:8080/teach/>
         Order allow,deny
         Allow from all
    </Proxy>

    ProxyPass /teach/ http://application.impactteachers.com:8080/teach/
    ProxyPassReverse /teach/ http://application.impactteachers.com:8080/teach/

因为我们正在将网站迁移到 Nginx 服务器,所以我们需要根据本文创建一条新规则:Apache ProxyPassReverse 的 Nginx 解决方案在您的帮助下,到目前为止这是当前的代码:

location /teach { 

    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://application.impactteachers.com:8080/teach;
    proxy_redirect          default;

}

我已测试过,但仍然显示相同的 404 错误。

答案1

尝试类似的事情:

upstream teach_backend {
    server application.impactteachers.com:8080 fail_timeout=2s;

    keepalive 32;
}


server {
    listen 80;
    server_name your_server_name.com;

      location /teach {
        proxy_http_version 1.1;
        proxy_set_header Connection "";

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header Host $host;

        proxy_pass http://teach_backend/teach;
        proxy_redirect http://teach_backend/teach /teach;
        #proxy_redirect default;

        #expires -1;
        #add_header Cache-Control "private";
    }

}

相关内容