【问题标题】:Nginx url rewrite error : [emerg] unexpected "}"Nginx url 重写错误:[emerg] 意外“}”
【发布时间】:2017-07-10 21:29:30
【问题描述】:

我正在尝试在 nginx 中重写 url,blow 是我的示例代码:

server {
    listen 80;
    server_name example.com;
    root   /full/server/path/to/your/cms;
    index  index.php;

    location / {
        try_files $uri $uri/ /phphandler
    }

    location /phphandler {
        internal;
        # nested location to filter out static items not found
        location ~ .php$ {
            rewrite ^/([^/]*)(.*) /$1 break;
            fastcgi_pass   127.0.0.1:8080;
            ...
        }
    }
}

我正在使用 DirectAdmin,当我从 linux 或 DirectAdmin 手动添加这段代码时,我遇到了同样的错误:

nginx:[emerg] 意外的“}” /usr/local/directadmin/data/users/admin/nginx.conf:178 nginx: 配置文件 /etc/nginx/nginx.conf 测试失败

注意:我从Here复制粘贴这段代码

而且我怀疑问题在于 3 个点(...)在哪里(在 fastcgi_pass 127.0.0.1:8080; 之后)我认为我应该在这里添加一些我不知道的东西?!

我在这段代码中缺少什么吗?
还是我面临这个错误的另一个问题?
提前感谢任何帮助我解决这个问题的人:)

【问题讨论】:

  • try_files 语句的末尾缺少;

标签: linux nginx url-rewriting centos directadmin


【解决方案1】:

问题是您在try_files 的末尾错过了;
但这也无济于事。
正如您提到的,您使用的是 DirectAdmin,我建议您使用 Nginx - Apache Reverse proxy
首先确保你有 custombuild 2

cd /usr/local/directadmin/custombuild
./build version

您应该会看到类似于以下内容的输出:

2.0.0-RC7 (rev: 863)

还要确保 directadmin 的版本不低于 1.45.2,否则将无法正常工作。

/usr/local/directadmin/directadmin v

运行此代码以使用 custombuild 构建 nginx + apache:

cd /usr/local/directadmin/custombuild
./build update
./build update_da
./build set webserver nginx_apache
./build nginx_apache
./build rewrite_confs

【讨论】:

    猜你喜欢
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    相关资源
    最近更新 更多