Search code examples
nginxnginx-configghost-blog

Installed GHOST on NGINX server and I broke it's ssl config file now NGINX won't restart


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name creationist.codes;
    root /var/www/creationist/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)

    ssl_certificate /etc/letsencrypt/creationist.codes/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/creationist.codes/creationist.codes.key;
    include /etc/nginx/snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2369;
        
    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

 proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass_request_headers on;

NGINX STATUS ->

root@creationistcodes:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2021-08-29 01:03:10 +07; 10s ago
     Docs: man:nginx(8)
  Process: 13970 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 956 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 15308 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 962 (code=exited, status=0/SUCCESS)
Aug 29 01:03:10 creationistcodes systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 29 01:03:10 creationistcodes nginx[15308]: nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/sites-enabled/creationist.codes-ssl.conf:28
Aug 29 01:03:10 creationistcodes nginx[15308]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 29 01:03:10 creationistcodes systemd[1]: nginx.service: Control process exited, code=exited status=1
Aug 29 01:03:10 creationistcodes systemd[1]: nginx.service: Failed with result 'exit-code'.
Aug 29 01:03:10 creationistcodes systemd[1]: Failed to start A high performance web server and a reverse proxy server.

I am not sure how this happened, I was just playing around trying to configure another server block and mistakenly added this below server block to my SSL block and restarted the server. With error being thrown out I re-edited it the way it was and Now I am not sure what to do! Please help!!

## For something.creationist.codes domain
server {
        listen 80;
        listen [::]:80;
        root /var/www/something.creationist.codes;
        index index.html;
        server_name something.creationist.codes;
}

Solution

  • The error message says "proxy_pass" directive is not allowed here ...:28. If you check the line :28 you can see that you have some statements which starts with proxy_pass http://websocket; ... and which are out of the server {...} scope.

    The proxy pass directive must be used in the scope of a location. So I would remove everything which is out of server {...}. Also make sure that the service defined at line 17 (proxy_pass http://127.0.0.1:2369;) is up and running.