我已经将以下全局conf添加到http块中的nginx.conf中。
其目的是将所有php应用程序(WordPress应用程序和PHPmyadmin应用程序)都包含在一个conf块中,而不是创建多个conf文件及其符号链接。
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?
发布于 2018-01-30 11:57:46
在一般配置之后放置一个server节,它将更有可能工作--配置是自上而下读取的,因此虚拟主机配置中的任何设置都会覆盖这些设置,如图中所示。
此外,您还可以使用nginx -t测试您的配置,这有助于显示错误所在。
发布于 2018-01-30 12:06:14
location {
try_files $uri $uri/ /index.php;
}在特定的位置块上没有location_match。只需将其改为
location ~ {
try_files $uri $uri/ /index.php;
}使您的配置文件有效。
解释:
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与给定位置完全匹配,则该块将被视为匹配。~:如果存在倾斜修饰符,则此位置将被解释为区分大小写的正则表达式匹配。*:如果使用倾斜和星号修饰符,则位置块将被解释为不区分大小写的正则表达式匹配。^~:如果存在一个克拉和倾斜修饰符,如果选择这个块作为最佳的非正则表达式匹配,则正则表达式匹配不会发生。
发布于 2018-01-30 12:06:25
你可以很容易地看到:
# nginx -t -c /tmp/nginx_test.conf
nginx: [emerg] invalid number of arguments in "location" directive in /tmp/nginx_test.conf:15我想他不喜欢location {。
https://serverfault.com/questions/894776
复制相似问题