【问题标题】:Converting apache rewrite rules to nginx将 apache 重写规则转换为 nginx
【发布时间】:2010-08-25 10:04:33
【问题描述】:

我想将一些 apache 规则转换为 nginx。

Apache 规则

deny from 127.1.1.4    
deny from 127.1.1.1
RewriteEngine on
RewriteRule    ^$                       /cgi-bin/index.cgi [L]
RewriteRule    ([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$     /cgi-bin/index.cgi?del=$1-$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^([0-9A-Za-z\-_]*)/?([0-9A-Za-z]{12})(/[^\/]*|)(\.html?|$)$  /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule    ^([0-9A-Za-z\-_]+)(/[0-9a-z\-_]*/?|$)$       /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld=$2 [L,NC]
RewriteRule    ^latest-files(\d*).html$             /cgi-bin/index.cgi?op=catalogue&page=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^([a-z0-9\-\_]+).html(.*)            /cgi-bin/index.cgi?op=page&tmpl=$1$2 [L]
ErrorDocument 404 /404.html

和nginx规则

rewrite ^/free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1 last;
rewrite  ^/(checkfiles|contact|login|links)\.html$ /cgi-bin/index.cgi?op=$1 last;
rewrite ^/premium\.html$ /cgi-bin/index.cgi?op=payments last;
rewrite ^/catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1 last;
rewrite ^/news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1 last;
rewrite ^/n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1 last;
rewrite ^/(faq|tos)\.html$ /cgi-bin/index.cgi?op=page&tmpl=$1 last;
rewrite "^/(?!tmp/)([0-9A-Za-z]{12})(\/.+|\.html?|$)" /cgi-bin/index.cgi?op=download1&id=$1&fname=$2 last;
rewrite "^/users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$)" /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2 last;
rewrite ^/pages/([a-z0-9\-\_]+).html /cgi-bin/index.cgi?op=page&tmpl=$1 last;

location / {
     root   /etc/nginx/html;
     index  index.html index.htm;
     rewrite ^  /cgi-bin/index.cgi last;
}

nginx 规则有问题(例如:images/* 和 css 文件 'link' 到 index.cgi)

你知道什么地方出了问题吗?

【问题讨论】:

    标签: apache nginx


    【解决方案1】:

    你只需要:

    location = / { root /etc/nginx/html; index index.html index.htm; rewrite ^ /cgi-bin/index.cgi last; }
    

    location / 表示以/ 开头的任何内容

    location = / 仅表示/

    【讨论】:

      【解决方案2】:

      查看以下网站可能会帮助您完成它:

      http://winginx.com/en/htaccess

      【讨论】:

      • 仅链接答案被认为是不好的做法。如果该文章或网站出现故障,此答案将变得毫无价值。我建议至少做一个简短的总结。
      猜你喜欢
      • 2016-06-18
      • 1970-01-01
      • 2014-06-30
      • 2016-08-09
      • 1970-01-01
      • 2013-01-23
      • 2018-05-06
      • 1970-01-01
      相关资源
      最近更新 更多