AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 455904
Accepted
Scott Klarenbach
Scott Klarenbach
Asked: 2012-12-07 18:06:28 +0800 CST2012-12-07 18:06:28 +0800 CST 2012-12-07 18:06:28 +0800 CST

nginx proxy_pass POST 404 错误

  • 772

我有 nginx 代理到应用程序服务器,具有以下配置:

location /app/ {
        # send to app server without the /app qualifier
        rewrite /app/(.*)$ /$1 break;
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:9001;
        proxy_redirect http://localhost:9001 http://localhost:9000;
    }

对 /app 的任何请求都会转到 :9001,而默认站点托管在 :9000。

GET 请求工作正常。但是每当我向 /app/any/post/url 提交 POST 请求时,它都会导致 404 错误。通过 GET /app/any/post/url 直接在浏览器中点击 url 会按预期点击应用服务器。

我在网上找到其他有类似问题的人并添加了

proxy_set_header Host $http_host;

但这并没有解决我的问题。

没有记录错误,访问日志如下:

# For http://localhost:9000 (no proxying)

127.0.0.1 - - [08/Dec/2012:12:29:28 -0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4"

# For http://localhost:9000/app/get/priorities (GET proxy)

127.0.0.1 - - [08/Dec/2012:12:32:17 -0800] "GET /app/get/priorities HTTP/1.1" 200 77 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4"

# When posting to http://localhost:9000/app/create/priority:

127.0.0.1 - - [08/Dec/2012:12:33:50 -0800] "POST /app/create/priority/ HTTP/1.1" 404 188 "http://localhost:9000/form-test.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4"

任何见解表示赞赏。

谢谢。

完整配置如下:

server {
    listen   9000; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /home/scott/src/ph-dox/html;
    # root ../html; TODO: how to do relative paths?
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /app/ {
        # rewrite here sends to app server without the /app qualifier
        rewrite /app/(.*)$ /$1 break;
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:9001;
        proxy_redirect http://localhost:9001 http://localhost:9000;
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }

}
nginx
  • 1 1 个回答
  • 6084 Views

1 个回答

  • Voted
  1. Best Answer
    Scott Klarenbach
    2012-12-09T13:14:31+08:002012-12-09T13:14:31+08:00

    我的错,问题不是 nginx,而是我的应用服务器。我使用的路由模块要求我明确指定请求方法(如果不是 get),这就是为什么它在发布时抛出 404 错误,但在直接访问浏览器 url 时却没有。

    • -1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve