【问题标题】:HTACCESS to NGINXHTACCESS 到 NGINX
【发布时间】:2014-03-04 15:05:41
【问题描述】:

我正在尝试将 htaccess 规则转换为 nginx。我是 nginx 新手,在线转换器也无济于事。

在 www 文件夹中

<IfModule mod_rewrite.c>
    RewriteEngine on

   RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

在公用文件夹内

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

有人可以帮我将这些 htaccess 规则转换为 nginx 吗?

【问题讨论】:

  • 当然。到目前为止,您尝试了什么,哪些没有按预期工作?您能否在您的 nginx 配置中添加相应的行,以便我们可以看到您所在的位置?
  • 我对 nginx 完全陌生,但我尝试使用 link 进行转换,但它没有按预期工作。
  • 那么请将结果添加到您的帖子中,并说明您的期望。对我来说,生成的结果看起来不错。

标签: apache .htaccess mod-rewrite nginx


【解决方案1】:

也许您的配置可能如下所示:

server {
  listen *:80;
  server_name source.example.com;
  server_tokens off; 

  location / {
        root /var/www;
  }

  location /public {
        root /var/www/public; # or so, put here your path to public dir
  }

  location @public {
    proxy_read_timeout 180;
    proxy_connect_timeout 180; 
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://host/public;
  }
}

我忘记了一些细节,但也许你需要类似的东西

【讨论】:

  • 这似乎没有回答这个问题。这如何实现 Apache 语法中 OP 给出的 URL 重定向?
  • 我认为这将有助于重定向,但你是对的 Naveen 不太可能使用 mod_proxy.. 不知道 htaccess
猜你喜欢
  • 2013-08-11
  • 1970-01-01
  • 1970-01-01
  • 2017-01-25
  • 2011-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多