skip to Main Content

When the user enters the url http://localhost:8000/Hello, I need to redirect him to http://localhost:8081/Hello.

Here is my attempt on the deploy.conf file:

server {
  listen 8000;

  location /Hello { 
    include uwsgi_params; 
    uwsgi_pass localhost:8081/Hello; 
    }
  }

But when I check nginx with: sudo nginx -t

I get this error:
nginx: [emerg] invalid host in upstream "localhost:8081/Hello" in /projects/challenge/deploy.conf

Please any help?

2

Answers


  1. the uwsgi_pass should point to the uswgi server so your config file would look like this:

    server {
      listen 8000;
    
      location /Hello { 
        include uwsgi_params; 
        uwsgi_pass localhost:8081; 
        }
      }
    
    Login or Signup to reply.
  2. The error is due to the improper format of the uwsgi_pass directive. The uwsgi_pass directive expects a URL or a Unix socket path as its argument, not a complete URL with a path.

    Try this way:

    server {
        listen 8000;
    
        location /Hello {
            include uwsgi_params;
            uwsgi_pass localhost:8081;  # Use only the base URL
        }
    }
    

    In this configuration, you’re instructing Nginx to proxy requests that match the /Hello path to the uWSGI server running on localhost:8081.

    Keep in mind that this Nginx configuration assumes that your uWSGI server is properly configured and running on localhost:8081.

    After making this change, you should reload Nginx for the changes to take effect:

    sudo systemctl reload nginx
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search