I'm migrating a website from a server that has Apache web-server to another server that is running Nginx web-server, and I wanted to convert the .htaccess files, the problem is not just the syntax but also the file name, is it also ".htaccess" or what?
问题:
回答1:
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
回答2:
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.
回答3:
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;
}