【nginx】 web-server 多文件入口访问

发布时间:2019-08-07 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了【nginx】 web-server 多文件入口访问脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

访问需求示例

需要访问如下 url
localhost/info.php
localhost/detail.php

服务端 server-root 目录结构:

➜  ~ tree public
public
├── detail.php
└── info.php

问题

我们习惯配置 nginxweb 服务为 单入口,即:

root /opt/PRo/public;
index index.php index.htML;

多入口 nginx 配置

利用 nginx 变量 $uri 动态配置 SCRIPT_NAME,实现 web 多入口访问

server {
    listen80;
    server_name localhost;
    index index.php;
    root /opt/pro/public;

    location ~* .php {
            try_files $uri $uri/ /$uri?$query_string;
            set $php_script $uri;
            include         fastcgi_params;
            fastcgi_pass    unix:/tmp/php-FPM.socket;
            fastcgi_param   SCRIPT_FILENAME         $document_root/$php_script;
            fastcgi_param   SCRIPT_NAME             /$php_script;
        }
}

脚本宝典总结

以上是脚本宝典为你收集整理的【nginx】 web-server 多文件入口访问全部内容,希望文章能够帮你解决【nginx】 web-server 多文件入口访问所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。