2017-05-07 171 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

可能的工作。