可以说我有一个像这样的path:
/var/www/myside/
该path包含两个文件夹…让我们说/static
和/manage
我想configurationnginx来访问:
/static
文件夹/
(例如http://example.org/ )这个文件夹有一些.html文件。
/manage
文件夹/manage
(例如http://example.org/manage )在这种情况下,这个文件夹包含Slim的PHP框架代码 – 这意味着index.php文件是在public
子文件夹(例如/ var / www / mysite /manage/public/index.php)
我已经尝试了很多组合,如
server { listen 80; server_name example.org; error_log /usr/local/etc/nginx/logs/mysite/error.log; access_log /usr/local/etc/nginx/logs/mysite/access.log; root /var/www/mysite; location /manage { root $uri/manage/public; try_files $uri /index.php$is_args$args; } location / { root $uri/static/; index index.html; } location ~ \.php { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; }
}
/
工作正确无论如何manage
不。 难道我做错了什么? 有谁知道我应该改变什么?
马修。
要使用像/manage
这样的URI访问像/var/www/mysite/manage/public
这样的路径,您将需要使用alias
而不是root
。 详情请参阅此文件 。
我假设您需要从两个根运行PHP,在这种情况下,您将需要两个location ~ \.php
块,请参阅下面的示例。 如果/var/www/mysite/static
没有PHP,则可以删除未使用的location
块。
例如:
server { listen 80; server_name example.org; error_log /usr/local/etc/nginx/logs/mysite/error.log; access_log /usr/local/etc/nginx/logs/mysite/access.log; root /var/www/mysite/static; index index.html; location / { } location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } location ^~ /manage { alias /var/www/mysite/manage/public; index index.php; if (!-e $request_filename) { rewrite ^ /manage/index.php last; } location ~ \.php$ { if (!-f $request_filename) { return 404; } fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } } }
^~
修饰符使前缀位置优先于同级别的正则表达式位置。 详情请参阅此文件 。
由于这个长期存在的bug , alias
和try_files
指令不在一起。
在使用if
指令时要注意这个警告 。