首页 > 解决方案 > Nginx - 位置块配置错误?

问题描述

我在启用站点的 example.conf 中有一个 location 块,应该将 /testing 路由到 503 错误 html 页面,但由于某种原因,它访问了我的应用程序而不是 nginx

[2020-06-30T20:36:13.821768 #6059] FATAL -- : [fc9cb972-f314-4a87-89d9-8334521767b3] ActionController::RoutingError (No route matches [GET] "/testing"): 

那是来自我的实际 Rails 应用程序的日志行 - 为什么它甚至比 nginx 路由到我认为我告诉它的地方?

我的 nginx .conf

server { listen 443 ssl;

        server_name status.* www.status.*;

        # SSL
        ssl_certificate_key /etc/nginx/ssl/server_example.com.key;

        # logging
        access_log /var/log/nginx/status.access.log;
        error_log /var/log/nginx/status.error.log;

# security
        include security.conf;

        # reverse proxy
        location / {
         if (-f /opt/staytus/staytus/maint.on) {
            return 503;
        }
        port_in_redirect off;
                proxy_pass http://example.com:8787/;
        }

error_page 503 @maintenance;
           location @maintenance {
                root /usr/share/nginx/html
                rewrite ^(.*)$ /Performing-Maintenace.html;
           }

location = /testing/ {
    return 500;
        }


}

server {
listen 80;
        server_name www.status.* status.* 11.22.123.456;
    root /opt/staytus/staytus/public;
    client_max_body_size 50M;


        # SSL
        ssl_certificate_key /etc/nginx/ssl/example.com.key;
        port_in_redirect off;
        return 301 https://example.com$request_uri;
   
    location @puma {
      proxy_intercept_errors on;
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto http;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://example.com:8787;
 }
}

标签: nginxcentos

解决方案


推荐阅读