【问题标题】:proxy_pass configuration in NGINXNGINX 中的 proxy_pass 配置
【发布时间】:2017-08-25 11:20:33
【问题描述】:

我试图弄清楚如何在 NGINX 中通过 proxy_pass 传递外部请求。特别是我想从http://example.com/documentation/加载Sphinx Documentation source,但实际上在重新启动NGINX服务器后我得到了502 Bad Gateway,可能是由于配置不正确。

这是我的示例配置:

server {

    listen 80;
    server_name example.com;
    root /var/www;

    location /documentation {

        proxy_pass http://example.com:8000;
        index index.php index.html index.htm;
    }

}

在我看来它应该可以工作,有什么建议吗?

考虑一下,如果我尝试在没有 NGINX 配置的情况下通过 ssh 控制台启动 Sphinx 源,它可以工作,但源路径是这样的:http://example.com:8000,不是显示它的最佳方式。

还因为我每次都需要通过控制台命令加载它:

sphinx-autobuild 源码构建/html --host http://example.com --port8000

我没有发现任何关于在主机的特定子文件夹中启动它的信息,例如子文件夹 /documentation。

[更新]

我尝试按照@Johnny Logan 的建议将example.com 替换为localhost 指令,我在地址栏中收到了带有这种奇怪结果请求的502 Bad Request:

http://example.com/documentation:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000:8000/

【问题讨论】:

    标签: nginx python-sphinx nginx-location proxypass


    【解决方案1】:

    看起来您又要连接到 example.com 了——我想您想在内部访问 8000 端口?您可能想在配置中替换“localhost”:

    server {
    
        listen 80;
        server_name example.com;
        root /var/www;
    
        location /documentation {
    
            proxy_pass http://localhost:8000;
            index index.php index.html index.htm;
        }
    
    }
    

    这样您也不需要打开端口 8000 -- 一切都通过端口 80 或 443。

    【讨论】:

    • 感谢您的回复,我已经尝试使用 localhost 但它仍然无法正常工作。这就是我将 example.com 设置为 proxy_pass 指令的原因。你看过我用来启动 sphinx 文档的 ssh 命令吗?这就是我使用端口 8000 的原因,在这种情况下它可以工作,但我想通过 NGINX 自动配置它,以便自动化流程并将位置设置在特定的子文件夹中。
    • 没有用过这个,但在黑暗中开枪:更改命令以启动 sphinx 以及使用 localhost 作为主机?类似“sphinx-autobuild source build/html --host localhost --port8000”或“sphinx-autobuild source build/html --host 127.0.0.1 --port8000”
    • ssh 指令工作正常,就是这个:sphinx-autobuild -B source build/html -H example.com -p8000 但我的问题是视图结果是example.com:8000 而不是@ 987654322@。另外主要问题是我总是必须使用这个 ssh 命令来使源上网。我需要可以自动处理这个命令请求的东西。
    猜你喜欢
    • 2012-12-31
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多