symfony 2.8生产app.php没有正确地从Nginx

时间:2017-09-07 21:47:08

标签: symfony nginx symfony-2.8

我有以下Nginx配置:

server {
    listen 80 default;
    listen [::]:80 default;
    server_name localhost;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name localhost;

    ssl_certificate /www/letsencrypt/easyPost/cert.pem;
    ssl_certificate_key /www/letsencrypt/easyPost/privkey.pem;

    ssl     on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    keepalive_timeout   70;

    root /var/www/html/web;

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

    location ~ ^/(widget|app)\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index app.php;
        send_timeout 1800;
        fastcgi_read_timeout 1800;
        #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_pass php:9000;
    }

    # 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;
    }
}

如果我致电https://localhost/https://localhost/app.php它可以正常工作,但我确定了其他无法覆盖的路线,例如https://localhost/app.php/postshttps://localhost/posts。调用FastCGI,Symfony返回404 not found。我想这是一个Nginx配置错误。有什么想法吗?感谢

更新

Symfony日志:

[2017-09-07 21:47:50] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /posts"" at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 176 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /posts\" at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php:176, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0):  at /var/www/html/app/cache/prod/appProdProjectContainerUrlMatcher.php:39)"} []

但这很奇怪,因为我有一个明确定义的路线:

/**
 * @Route(
 *     "/posts.{_format}",
 *     name="posts",
 *     defaults={"_format": "json"},
 *     requirements={
 *         "_format": "json"
 *     }
 * )
 */
public function getPostsAction($_format, Request $request)

root@b86232f28c81:/var/www/html# app/console debug:router --env=prod
 ---------- -------- -------- ------ ------------------ 
  Name       Method   Scheme   Host   Path              
 ---------- -------- -------- ------ ------------------ 
  homepage   ANY      ANY      ANY    /                 
  posts      ANY      ANY      ANY    /posts.{_format}  
 ---------- -------- -------- ------ ------------------ 

0 个答案:

没有答案