I'm trying to configure a mediawiki instance with Nginx. I've done it before, on another server, and it worked fine there. However, when I copy the same nginx vhost file over to this server (changing relative bits like the server_name), nginx gives me the following error:
nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/wiki.[site].com:48
On my other server, this gives me no errors at all and works exactly as intended. I'm using the same version of nginx (1.14) on either server, and the nginx.conf files are identical.
I'm completely stumped, any help would be massively appreciated.
The full vhost file is as follows:
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;
}
}
Although, my use case is load balancing, the principle still applies , it's preferable to add the upstream clause configuration on a separate file located at the etc/nginx/sites-available/
folder . For reference , below is the nginx.conf file that I used :
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
And the file (called Default) that I created on the sites-available
folder
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/cert-key.pem;
server_name my_dummy_server;
location / {
proxy_pass http://myapp1;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
upstream myapp1
{
server 192.168.1.154;
server 192.168.1.164;
server 192.168.1.174;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With