简体   繁体   English

将Apache重写规则转换为Nginx

[英]Converting apache rewrite rules to nginx

I want to convert a few apache rules to nginx. 我想将一些Apache规则转换为Nginx。

Apache rules 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

And nginx rules 和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;
}

There is something wrong with nginx rules (for example: images/* and css files 'link' to index.cgi) Nginx规则有问题(例如:images / *和CSS文件“链接”到index.cgi)

Any idea about what might be wrong? 关于什么可能是错的任何想法?

You just need: 您只需要:

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

location / means anything that begins with / location /表示以/开头的任何内容

location = / means just / location = /表示/

Check out the following site that might help you to get it done: 请访问以下网站,该网站可能会帮助您完成任务:

http://winginx.com/en/htaccess http://winginx.com/cn/htaccess

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM