脚本宝典收集整理的这篇文章主要介绍了启用了PHP的Nginx通配符子域,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
server { listen 80 default_server; listen [::]:80 default_server IPv6only=on; index index.htML index.htm; server_name ~^(.*)\.example\.com$; root /var/www/$1; }
我的目录结构设置为:
/var/www /subdomain1 /subdomain2 /subdomain3
如果我访问subdomain1.example.com,subdomain2.example.com或subdomain3.example.com,则会提供相关子目录中的index.html文件.到目前为止完美无缺.
当我尝试使用PHP文件时,问题出现了.首先,我将index指令更改为index index.PHP,然后在server指令中添加以下内容:
location ~ \.PHP${ try_files $uri /index.PHP =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; }
Nginx接受此配置没有任何问题.但是,如果我尝试访问subdomain1.example.com然后我从Nginx收到404错误,但错误日志中没有任何内容.
如果我将try_files指令更改为try_files $uri /subdomain1/index.PHP = 404;然后它正确执行subdomain1目录中的index.PHP文件,但这显然违背了目的,因为我希望它作为通配符工作.问题是我无法访问location指令中父指令的$1变量.
server { ... server_name ~^(?<subdomain>.+)\.example\.com$; root /var/www/$subdomain; index index.PHP; location / { try_files $uri $uri/ /index.PHP; } location ~ \.PHP${ try_files $uri /index.PHP; ... } }
以上是脚本宝典为你收集整理的启用了PHP的Nginx通配符子域全部内容,希望文章能够帮你解决启用了PHP的Nginx通配符子域所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。