【问题标题】:I need to translate my htaccess for nginx to work我需要翻译我的 htaccess 才能让 nginx 工作
【发布时间】:2014-04-07 22:23:00
【问题描述】:

好吧,我在旧的 apache 配置(htaccess)中有这个 mod_rewrite,我正在尝试将配置设置为 nginx,但我无法真正理解它在 nginx 中的实际工作原理,我是所有这些 nginx 的新手东西,谁能帮我翻译一下……在此先谢谢你了。

当前 htacces 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^(/static/)

    RewriteRule . /app.php [L]
</IfModule>

虚拟配置文件test.url:

server {
    server_name test.url;
    access_log /var/www/test.url/logs/access.log;
    error_log /var/www/test.url/logs/error.log;
    root /var/www/test.url/public_html/blank;

    location / {
        app.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/test.url/public_html/$
    }
}

【问题讨论】:

    标签: apache .htaccess mod-rewrite nginx


    【解决方案1】:

    代替:

    location / {
        app.php;
    }
    

    试试:

    location /static/ {
        # do nothing, we don't want to rewrite /static/
    }
    
    location / {
        try_files $uri $uri/ /app.php
    }
    

    【讨论】:

    • 谢谢!你让我很开心;)我开始明白这一点。只是一件事,你忘记了“;”在 "try_files... 的末尾
    猜你喜欢
    • 2012-07-13
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 2015-02-01
    • 1970-01-01
    • 2019-03-15
    相关资源
    最近更新 更多