Ubuntu

Nginx 伺服器位置配置

  • November 30, 2013

我希望域 example.com/a/1234/asdf、example.com/a/7890/qwer 、…、example.com/a/* 從同一索引文件 /var/www/ 提供網頁foo/bar/index.php

我的 nginx 是這樣配置的:

server {

       listen 80;
       root /var/www;
       index index.php;

       rewrite */a/(.*) /var/www/foo/bar/index.php;

       location ~ \.php$ {
               try_files $uri =404;
               fastcgi_split_path_info ^(.+\.php)(/.+)$;
               fastcgi_pass unix:/var/run/php5-fpm.sock;
               fastcgi_index index.php;
               include fastcgi_params;
       }
}

當我轉到 example.com/a/1234/asdf 時,我收到 404 not found 錯誤。

您可能沒有文件/var/www/var/www/foo/bar/index.php。所以當然找不到。請記住,這些路徑是相對於文件的root

你可能想要這樣的東西:

rewrite */a/(.*) /foo/bar/index.php last;

引用自:https://serverfault.com/questions/558404