简体   繁体   English

更改要与Nginx一起使用的Apache .htaccess文件

[英]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/ http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

It is not 100% accurate but it's pretty good base 它不是100%准确,但相当不错的基础

Also, here's a link about converting the rules: 另外,这是有关转换规则的链接:

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

This one can help a little: 这可以帮助一点:

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

EDIT: 编辑:

The file name should be nginx.conf 文件名应为nginx.conf

Nginx does not have support for .htaccess files. Nginx 不支持.htaccess文件。

But .htaccess files are bad. 但是.htaccess文件不好。 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. 这是一种将apache配置的各个部分放置在文件系统上的任何位置,并告诉apache在每次请求时检查文件系统,以查看是否没有适当的配置。 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. .htaccess文件的唯一实际用法是,如果您是主机提供商,并且希望允许用户进行某些Web服务器配置,则将一小部分配置委派给用户。

Nginx configuration is compiled when nginx restart. 重新启动nginx时会编译nginx配置。 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. 当然,如果您确实不关心信息泄露问题(例如用户掌握您的Web服务器配置),但是可以将几个文件放入Web目录中,但是它们与.htaccess相同,则每次请求时都进行读取完成,不是以nginx方式。

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

You can't do this. 你做不到 You shouldn't. 你不应该 If you need .htaccess, you're probably doing it wrong. 如果需要.htaccess,则可能做错了。

Look at here: 看这里:

https://www.digitalocean.com/community/questions/configuring-multiple-domains-and-subdomains-dns-nginx-issues-abound 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;      
} 

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

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