Nginx 代理和 symfony 4 应用程序

Nginx 代理和 symfony 4 应用程序

我正在部署可通过代理访问的 Symfony 4 应用程序:https://proxydomain.com/application

当使用不带尾部斜杠的 URL 访问时,应用程序可以正常工作:https://proxydomain.com/application但是当我在末尾添加斜杠时(https://proxydomain.com/application/)nginx 返回 404。

以下是这两个示例的日志片段:

172.20.83.254 - - [11/Jun/2019:16:10:06 +0200] "GET / HTTP/1.1" 200 316 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/74.0.3729.169 Chrome/74.0.3729.169 Safari/537.36"
172.20.83.254 - - [11/Jun/2019:16:10:03 +0200] "GET // HTTP/1.1" 404 522 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/74.0.3729.169 Chrome/74.0.3729.169 Safari/537.36"

这是我的 nginx 配置文件:

server {
        server_name _;
        root /var/www/application/public;

        location / {
                # try to serve file directly, fallback to app.php
                try_files $uri /index.php$is_args$args;
        }

        # PROD
        location ~ ^/index\.php(/|$) {
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                # When you are using symlinks to link the document root to the
                # current version of your application, you should pass the real
                # application path instead of the path to the symlink to PHP
                # FPM.
                # Otherwise, PHP's OPcache may not properly detect changes to
                # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
                # for more information).
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                # Prevents URIs that include the front controller. This will 404:
                # http://domain.tld/app.php/some-path
                # Remove the internal directive to allow URIs like this
                internal;
   }

   # return 404 for all other php files not matching the front controller
   # this prevents access to other php files you don't want to be accessible.
   location ~ \.php$ {
         return 404;
   }

   error_log /var/log/nginx/application_error.log;
   access_log /var/log/nginx/application_access.log;
}

你知道我该怎么做才能让它发挥作用吗?

相关内容