首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Nginx全局conf破坏Nginx (更新)

Nginx全局conf破坏Nginx (更新)
EN

Server Fault用户
提问于 2018-01-30 11:46:54
回答 3查看 841关注 0票数 0

我已经将以下全局conf添加到http块中的nginx.conf中。

其目的是将所有php应用程序(WordPress应用程序和PHPmyadmin应用程序)都包含在一个conf块中,而不是创建多个conf文件及其符号链接。

代码语言:javascript
运行
复制
http {
    ..........................................
    server {
        listen 80 default_server;
        root /var/www/$host;
        location / {
            index index.php index.html index.htm;
        }
        location ~ {
            try_files $uri $uri/ /index.php;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    ..........................................
}

我的问题

这种配置破坏了系统--只要它在nginx.conf内部,系统就会中断。

完整(更新)的nginx.conf 在这里可以看到

nginx -t中唯一的错误是关于这一行listen 80 default_server;,它说:

重复默认服务器0.0.0.0:80 in /etc/nginx/nginx.conf:65

我的问题

为什么我的全球代码破坏了Nginx?

EN

回答 3

Server Fault用户

发布于 2018-01-30 11:57:46

在一般配置之后放置一个server节,它将更有可能工作--配置是自上而下读取的,因此虚拟主机配置中的任何设置都会覆盖这些设置,如图中所示。

此外,您还可以使用nginx -t测试您的配置,这有助于显示错误所在。

票数 0
EN

Server Fault用户

发布于 2018-01-30 12:06:14

代码语言:javascript
运行
复制
  location {
            try_files $uri $uri/ /index.php;
        }

在特定的位置块上没有location_match。只需将其改为

代码语言:javascript
运行
复制
            location ~ {
                    try_files $uri $uri/ /index.php;
            }

使您的配置文件有效。

解释:

代码语言:javascript
运行
复制
Location blocks generally take the following form:

location optional_modifier location_match {

    . . .

}
The location_match in the above defines what Nginx should check the request URI against. The existence or nonexistence of the modifier in the above example affects the way that the Nginx attempts to match the location block. The modifiers below will cause the associated location block to be interpreted as follows:

(none): If no modifiers are present, the location is interpreted as a prefix match. This means that the location given will be matched against the beginning of the request URI to determine a match.

=:如果使用等号,则如果请求URI与给定位置完全匹配,则该块将被视为匹配。~:如果存在倾斜修饰符,则此位置将被解释为区分大小写的正则表达式匹配。*:如果使用倾斜和星号修饰符,则位置块将被解释为不区分大小写的正则表达式匹配。^~:如果存在一个克拉和倾斜修饰符,如果选择这个块作为最佳的非正则表达式匹配,则正则表达式匹配不会发生。

票数 0
EN

Server Fault用户

发布于 2018-01-30 12:06:25

你可以很容易地看到:

代码语言:javascript
运行
复制
# nginx -t -c /tmp/nginx_test.conf
nginx: [emerg] invalid number of arguments in "location" directive in /tmp/nginx_test.conf:15

我想他不喜欢location {

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/894776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档