【问题标题】:Apply rewrite rule to nginx vhost from apache vhost从 apache vhost 将重写规则应用于 nginx vhost
【发布时间】:2016-03-03 00:35:46
【问题描述】:

我正在用 nginx 做一些测试。

他工作得很好,但我无法从 apache 应用一些重写规则,而且 nginx 文档并不容易。

目标:所有内容都必须在 /index.php 文件上重写,而不是额外和管理员。

如果我浏览到http://server/extra/someThing,没关系,调用了controller.php文件。

但是对于/adminer,我只是想防止/adminer被最后一条规则重写。

location / {
    rewrite ^/extra /extra/controller.php break;
    #rewrite ^/adminer - break;
    rewrite ^/ /index.php break;
}

任何帮助将不胜感激:)

【问题讨论】:

    标签: apache .htaccess nginx


    【解决方案1】:

    您可以使用单独的位置块来划分您的重写逻辑。例如:

    location / {
        try_files $uri $uri/ /index.php;
    }
    location /extra {
        try_files $uri $uri/ /extra/controller.php;
    }
    location /adminer {
        try_files $uri $uri/ =404;
    }
    

    请参阅thisthis 了解更多信息。

    【讨论】:

    • 谢谢,但是“location /”不起作用并且php文件没有执行,我需要将它更改为“location ~”,然后是“location /extra”和“location /adminer”使用 /index.php 文件。没有 ~ 没有任何作用。
    • 终于完成了,可能不是最好的方法,但它有效:location /adminer { try_files $uri =404; } 位置 ~ \.php$ { 返回 403; } 位置 ~ { 重写 ^/extra /extra/controller.php 中断; try_files $uri $uri/ /index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;包括 fastcgi_params; } 感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2020-05-13
    • 2021-06-16
    • 2014-11-17
    • 1970-01-01
    • 2017-04-01
    • 2016-03-24
    • 2016-10-13
    • 2014-02-22
    相关资源
    最近更新 更多