我有一个子域,我想保留我正在处理的项目,以便向客户展示这些项目.
这是/ etc / Nginx / sites-available / projects中的配置文件:
server { listen 80; server_name projects.example.com; access_log /var/log/Nginx/projects.example.com.access.log; error_log /var/log/Nginx/projects.example.com.error.log; location / { root /var/www/projects; index index.html index.htm index.PHP; } location /example2.com { root /var/www/projects; auth_basic "Stealth mode"; auth_basic_user_file /var/www/projects/example2.com/htpasswd; } location /example3.com/ { index index.PHP; if (-f $request_filename) { break; } if (!-f $request_filename) { rewrite ^/example3\.com/(.*)$/example3\.com/index.PHP?id=$1 last; break; } } location ~ \.PHP { root /var/www/mprojects; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/Nginx/fastcgi_params; } }
我希望能够在子文件夹中放置不同的PHP引擎(wordpress,getsimple等).这些引擎有不同的querry参数(id,q,url等),所以为了使preety URL工作,我必须重写.
但是,上面不起作用.这是我得到的回应:
Warning: Unknown: Filename cannot be empty in Unknown on line 0 Fatal error: Unknown: Failed opening required '' (include_path='.:/usr/local/lib/PHP') in Unknown on line 0
如果我取出“location /example3.com/”规则,那么一切正常但没有任何可靠的URL.
请帮忙.
配置基于这篇文章:
https://stackoverflow.com/questions/2119736/cakephp-in-a-subdirectory-using-nginx-rewrite-rules
你不能在重写的第二部分中逃避句点(.):
原文链接:https://www.f2er.com/php/139258.htmlrewrite ^/example3\.com/(.*)$/example3\.com/index.PHP?id=$1 last;
应该
rewrite ^/example3\.com/(.*)$/example3.com/index.PHP?id=$1 last;
但是你的id是什么样的?如果它是一个数字,你可以试试这个:
location /example3.com/ { index index.PHP; rewrite "^/example3\.com/([0-9]+)$" /example3.com/index.PHP?id=$1 break; }