【问题标题】:Problem in converting .htaccess mod_rewrite to nginx directive将 .htaccess mod_rewrite 转换为 nginx 指令时出现问题
【发布时间】:2021-01-01 05:04:50
【问题描述】:

我很难将此 apache 重写规则转换为 nginx:

<IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymLinks
    Options -Indexes

    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule . index.php [L,QSA]
</IfModule>

我尝试过的 答:

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

乙:

 location  / {
        try_files $uri $uri/ index.phps$args;
    }

但是,A 确实为任何 /path 提供 404 错误,而 B 适用于 /path/to/somewhere,但下载 /path

这是我完整的虚拟主机:

server {
        listen 8000;
        root /var/www/myphpapp;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name localhost;
        #autoindex off;

        location / {
                try_files $uri $uri/ index.php$is_args$args; #A
                #try_files $uri $uri/ /index.php?$args; #B

        }


        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

所以我想知道正确的 nginx 指令是什么?

【问题讨论】:

    标签: php .htaccess nginx


    【解决方案1】:

    我认为有一个错字。你错过了一个斜线:

             try_files $uri $uri/ /index.php$is_args$args;
    

    【讨论】:

    • 好吧,当我使用/index.php$is_args$args 时,它只会在我访问/signup 页面时下载index.php
    • 也就是说,nginx将请求转发到index.php,但是不知道如何执行该文件。所以现在问题出在php设置中。你能分享更多关于你的设置的信息吗?
    猜你喜欢
    • 2016-12-13
    • 2013-02-02
    • 2021-11-26
    • 2020-12-23
    • 1970-01-01
    • 2012-07-19
    • 2018-07-10
    • 2017-08-02
    • 2011-05-07
    相关资源
    最近更新 更多