【问题标题】:Htaccess and nginx convertingHtaccess 和 nginx 转换
【发布时间】:2016-01-31 17:11:09
【问题描述】:

我正在转换这个 htaccess 文件htaccess file

到 nginx 使用

http://winginx.com/ru/htaccess

但不明白我应该在哪里粘贴结果。我创造了 包含文件

包括 /etc/nginx/myfile

并在那里粘贴文件,但是当我重新加载(重新启动)Nginx 时它失败了。

你能帮帮我吗?

【问题讨论】:

  • 欢迎来到 StackOverflow。请在此处粘贴信息,尤其是。还有消息,为什么 nginx 无法重新启动。如果没有直接发出,那应该在一些日志文件中找到。

标签: .htaccess nginx


【解决方案1】:

我怀疑这些 apache .htaccess 转换器没有充分利用 nginx 的独特功能。我建议尝试这样的事情:

server {
    listen  80  default_server;
    server_name  _;

    root    /var/www/example.com;
    index   index.php;

    # if the file or directory doesn't exist, serve /index.php
    try_files $uri $uri/ /index.php;

    # if the request is exactly /sitemax.xml, serve sitemap_xml.php
    location = /sitemax.xml {
        try_files /modules/sitemap/sitemap_xml.php =404;
    }

    # hide regex location in a prefix location to avoid confusion
    # introduced by multiple regex locations
    location /pages-print {
        location ~ ^/pages-print(\d+) {
            try_files /modules/pages/print.php?page=$1 =404;
        }
    }
}

【讨论】:

    【解决方案2】:

    我找到了解决方案。我尝试将转换器的结果粘贴到 nginx.conf 中,但这是错误的。我改为在 /etc/nginx/ 中创建文件并将其命名为 htac.rules(我认为您如何命名它并不重要)。

    然后我打开文件 etc/nginx/sites-enabled/default 并在位置 / 插入包含 /etc/nginx/htac.rules

    所以。

    在 htac.rules 中我插入了没有位置 / {...}的转换结果

    而且,是的。它解决了我的问题。

    感谢大家帮助我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-10
      • 2017-01-25
      • 2017-08-02
      • 2011-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多