Question

Unknown directive "proxy_pass"

Posted March 20, 2021 958 views
NginxUbuntu 20.04DigitalOcean Droplets

Hello,

This is my first droplet, using Ubuntu 20.04, and I’ve followed all the steps for setting up everything, but I get the error unknown directive “proxy_pass” in “/etc/nginx/sistes-enabled/my-website” when starting/restarting nginx. Is there a way to fix this?

Thanks

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hi there,

I believe that the proxy_pass directive needs to be specified inside the location{} directive.

If this does not work, feel free to share your Nginx Server Block here so I could advise you further.

Regards,
Bobby

@bobbyiliev thanks for the reply, bellow it’s my server configuration with the location directive.

Upon further inspection, running nginx -V I see no reference to the module ngx_http_proxy_module.

server {
    # Listen HTTPS
    listen 80;
    listen [::]:80;
    server_name grupovapo.com;

    # Static Root
    location / {
        root /home/primariu/grupo-vapo-admin;
    }

    # Strapi API
    location /api/ {
        rewrite ^/api/?(.*)$ /$1 break;
        proxy_pass http://strapi;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $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_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }

    # Strapi Dashboard
    location /dashboard {
        proxy_pass http://strapi/dashboard;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $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_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }
}

Best regards

edited by MattIPv4
  • Hi there,

    Do you by any chance remember how you installed Nginx? I run Ubuntu 20.04 with Nginx for my personal site and I installed Nginx with apt and the proxy module seems to be working as expected.

    The Nginx configuration also looks good.

    Do you get any errors when running:

    sudo nginx -t
    

    Regards,
    Bobby