如何在Nginx上添加自定义PHP位置

问题描述

我已经配置了一个Yii2高级模板站点(高级意味着2个站点:第一个是前端站点,第二个是管理区域)

我的前端(Nginx的根)位于/ public_html,而我的管理员位于/ public_html / admin。

除了以“不同方式”开发的两个端点外,几乎所有东西都可以工作。

我认为这是我的问题所在:通常,任何请求都将指向www.mysite.com/ / index,而index.PHP文件将接受该请求,然后让PHP决定如何处理给定的申请路线。

很遗憾,我有两个www.mysite.com/ / action 端点(一个在前端,另一个管理员)(思维索引已由action代替)。所以现在Nginx正在路由该请求以建立索引,但应该将其指向操作。或者至少我是这样看的。阿米赖特?

这是我的意思:

常规前端路线

  • 请求网址:www.mysite.com /索引
  • 所有到达public_html / index.PHP但由Nginx location /服务的路线

常规管理路线

非常规前端路由:

  • 请求网址:www.mysite.com / not_index
  • Nlix location /
  • 路由到public_html / index.PHP 仍在投放

非常规后端路由:

  • 请求网址:www.mysite.com/admin/ not_index
  • Nlix location /admin
  • 路由到public_html / admin // index.PHP 仍在投放 我认为这是我的问题

“很明显”,我的两个非常规路线都解析为404找不到。我无法为此找到解决方案。我已经待了好几天了...

这是我的Nginx.conf:

server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    root /var/www/mysite/public_html;
    index index.PHP index.html index.htm;
    server_name localhost;

    location /admin {
        root /var/www/mysite/public_html/admin;
        index index.PHP;
        try_files $uri  /admin/index.PHP$is_args$args ;

        location = /admin/ {
            return  301 /admin;
        }

        location = /admin/frontend-users/search-influencers {
            try_files  /admin/$uri /admin/$uri.PHP;
        }
    }


    location / {
        root /var/www/mysite/public_html;
        try_files $uri /index.PHP$is_args$args;
    }

    location ~ \.PHP$ {
        try_files $uri =404;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/PHP/PHP7.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~* \.(css|map|mp3|mp4|js|jpg|jpeg|png|gif|bmp|ico|mov|swf|pdf|zip|rar)$ {
        access_log  off;
        log_not_found  on;
        try_files  $uri /public_html/$uri =404;
    }
}

我在做什么错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)