【问题标题】:nginx configuration for three types of .php files三种.php文件的nginx配置
【发布时间】:2022-01-13 02:55:49
【问题描述】:

我有这样三种类型的网址:

http://log.cb.gq/index.php/creative-thinking-workshop-de

http://log.cb.gq/work.php/creative-thinking-workshop-de

http://log.cb.gq/cat.php/creative-thinking-workshop-de

而nginx conf是这样的

location / {
            try_files $uri $uri/ /index.php$is_args$args;
            #rewrite ^/([a-zA-Z0-9]+)/?$ /index.php?$1;
    }

并且只有第一个 url 即 index.php 有效。我怎样才能使这三个工作都起作用

【问题讨论】:

  • 其他 URL 会发生什么?您是否从 Nginx 获得某个状态码?还是你得到一个 PHP 级别的错误?
  • 它显示 index.php 的内容和 work.php/creative-thinking-workshop-de 的路线以及 ofcource no css
  • 但它在没有 htaccess 的 apache 的 localhost 上工作正常
  • 所以页面正在加载,而不是资源?如果是这样,请检查服务器和/或浏览器控制台日志是否有错误,并查看它们尝试加载的路径。
  • 正确的解决方案是更改 location ~ \.php$ 块,使其与您问题中的 URI 匹配。 For example 与:location ~ [^/]\.php(/|$)

标签: php nginx nginx-config


【解决方案1】:

位置/{ try_files $uri $uri/ /index.php$is_args$args; }

位置 /work.php { try_files $uri $uri/ /work.php$is_args$args; }

位置 /cat.php { try_files $uri $uri/ /cat.php$is_args$args; }

这对我有用

【讨论】:

    猜你喜欢
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2014-08-31
    • 2016-05-20
    • 1970-01-01
    • 2022-06-11
    • 1970-01-01
    相关资源
    最近更新 更多