简体   繁体   中英

Change Apache .htaccess file to be used with Nginx

我正在将网站从具有Apache Web服务器的服务器迁移到另一台运行Nginx Web服务器的服务器,我想转换.htaccess文件,问题不仅仅在于语法,还在于文件名。它还是.htaccess还是什么?

Here's a tool I use:

http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

It is not 100% accurate but it's pretty good base

Also, here's a link about converting the rules:

http://nginx.org/en/docs/http/converting_rewrite_rules.html

This one can help a little:

http://wiki.nginx.org/HttpRewriteModule#rewrite

EDIT:

The file name should be nginx.conf

Nginx does not have support for .htaccess files.

But .htaccess files are bad. It's a way to put parts of the apache configuration erverywhere on the filesystem and to tell apache to check the filesystem at every request to see if you do not have some special configuration in place. The only real usage of .htaccess file is to delegate a small part of the configuration to the user if you are a host provider and wanted to allow some web server configuration for your users.

Nginx configuration is compiled when nginx restart. Of course you can include several files that you can put in your web directory if you really do not care about information disclosure problems (like users seing your web server configuration), but having the same thing as a .htaccess, read each time a request is done, is not in the nginx way.

http://wiki.nginx.org/LikeApache-htaccess :

You can't do this. You shouldn't. If you need .htaccess, you're probably doing it wrong.

Look at here:

https://www.digitalocean.com/community/questions/configuring-multiple-domains-and-subdomains-dns-nginx-issues-abound

server {  
    server_name  domain1.com;  
    rewrite ^(.*) http://www.domain1.com$1 permanent;  
}  

server {  
    listen 80 default_server;  
    listen [::]:80 default_server ipv6only=on;  
    root /home/user/www/domain1;  
    index index.php index.html index.htm;  

    server_name www.domain1.com;  

    include hhvm.conf;      
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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