Nginx Symfony子目录配置

时间:2017-05-07 22:17:12

标签: symfony nginx configuration subdirectory

server {
    listen <...:...>;
    server_name <...>;
    root /var/www/html/myserver;

    location /myproject {
        try_files $uri /myproject/web/app.php$is_args$args;
    }
    location ~ ^/myproject/web/(app_dev|config)\.php(/|$) {
        fastcgi_pass <...php-fpm...>;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    location ~ ^/myproject/web/app\.php(/|$) {
        fastcgi_pass <...php-fpm...>;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

}

当我尝试myserver.com/myproject/web

时,我可以看到我的项目

我希望在myserver.com/myproject访问我的项目。

但是这个网址给了404(在Symfony中):

No route found for "GET /myproject/"

我在配置文件中添加了这个重写规则,但它不起作用:

rewrite ^/myproject(/|$)$ /myproject/web last;

0 个答案:

没有答案