2017-05-07 132 views
0
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/webNginx的Symfony的子目录配置

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

但这个网址给404(在Symfony的):

No route found for "GET /myproject/" 

我加入这个重写规则在我的配置文件,但它不工作:

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

回答

0

你的配置看起来除了你的根OK 。其他路径然后应该改变:

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

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

location ~ \.php$ { 
... 

您可以看到the NGINX config docs作为参考。 如果你想使用你现有的配置,那就试试这个网址:

myserver.com/web

可能的工作。