Nginx Symfony子目录配置

问题描述 投票:0回答:1
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项目。

但是这个URL给出了404(在Symfony中):

No route found for "GET /myproject/"

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

rewrite ^/myproject(/|$)$ /myproject/web last;
symfony nginx configuration subdirectory
1个回答
0
投票

您的配置看起来不错,但根目录除外。 然后其他路径应更改:

root /var/www/html/myserver/web;

location / {
  ...
}
location ~ ^/(app_dev|config)\.php(/|$) {
  ...
}
location ~ ^/app\.php(/|$) {
  ...
}

location ~ \.php$ {
...

您可以查看NGINX配置文档以供参考。 如果要使用现有配置,请尝试以下URL:

myserver.com/web

那可能行得通。

© www.soinside.com 2019 - 2024. All rights reserved.