【发布时间】:2018-08-02 16:19:07
【问题描述】:
我正在尝试使用 Nginx 配置一个 mediawiki 实例。我以前在另一台服务器上做过,它在那里工作得很好。但是,当我将相同的 nginx vhost 文件复制到此服务器时(更改 server_name 等相关位),nginx 给我以下错误:
nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/wiki.[site].com:48
在我的另一台服务器上,这完全没有错误,并且完全按预期工作。我在任一服务器上使用相同版本的 nginx(1.14),并且 nginx.conf 文件是相同的。
我完全被难住了,任何帮助将不胜感激。
完整的vhost文件如下:
server {
listen 80;
listen [::]:80;
server_name wiki.[site].work;
return 301 https://wiki.[site].work$request_uri;
}
server {
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
server_name wiki.[site].work;
root /var/www/wiki.[site].work;
index index.php;
autoindex off;
ssl_certificate /etc/letsencrypt/live/[site].work/cert.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/[site].work/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
client_max_body_size 5m;
client_body_timeout 60;
location / {
index index.php5;
rewrite ^/([^?]*)(?:\?(.*))? /index.php5?title=$1&$2 last;
}
location ~ \.php5?$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_param HTTPS on;
}
location ~ \.php?$ {
try_files $uri =404;
fastcgi_param HTTPS on;
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
upstream php5-fpm-sock {
server unix:/var/run/php5-fpm.soc;
fastcgi_param HTTPS on;
}
}
【问题讨论】:
-
您在
server块中有一个upstream指令。它需要在server块之外。请参阅 the documentation here 并注意 context。 -
@RichardSmith 非常感谢!就我而言,我将它写在
http块的外部,我收到了相同的错误消息。这个,http { upstream { ... ) ... server { ... } },是正确的放入方式。