根据configuration, site.com应该默认打开html/web/index.php ,但site.com/ticket应该打开html/ticket/index.php 。 ticket和web文件夹位于html 。
server { listen 80; return 301 https://$host$request_uri; } server { add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; server_name site.com; server_tokens off; root /usr/share/nginx/html/web; location / { index index.php; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ /\.ht { deny all; } location /ticket { root /usr/share/nginx/html/ticket; index index.php index.html index.htm; } }
它会打开web/index.php ,但是对于/ticket它说Not found 。
UPDATE
上面看起来在/usr/share/nginx/html/ticket/ticket/index.php
我也试过了
location /ticket { root /usr/share/nginx/html; index index.php index.html index.htm; }
和
location /ticket { alias /usr/share/nginx/html/ticket; index index.php index.html index.htm; }
这两个configuration都在/usr/share/nginx/html/web/ticket/index.php查找。
它应该在/usr/share/nginx/html/ticket/index.php
我想,问题在于FastCGI
解
问题出在FastCGIconfiguration中
try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi_params;
这将工作。 我已经testing过了。
server { server_name site.com; server_tokens off; root /usr/share/nginx/html/web; location / { index index.php; } location /ticket { index index.php; alias /usr/share/nginx/html/ticket/; if (-f $request_filename) { break; } if (-d $request_filename) { break; } rewrite (.*) /ticket/index.php?$query_string; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
你需要使用alias指令。 nginx不会在用alias指定的目录之后添加完整的规范化URI,就像使用root 。
所以,你的块看起来像:
location /ticket { alias /usr/share/nginx/html/ticket; index index.php index.html index.html; }
请参阅root指令的文档。 在内部的location ,它仍然是根相对而不是相对于特定的位置。
设置请求的根目录。 例如,具有以下configuration
location /i/ { root /data/w3; }
/data/w3/i/top.gif文件将被发送以响应/i/top.gif请求。
因此,你应该有:
location /ticket/ { root /usr/share/nginx/html; index index.php index.html index.htm; }
否则,它会尝试访问/usr/share/nginx/html/ticket/ticket/index.php 。