Bumeranghc
Bumeranghc

Reputation: 61

NGINX as reverse proxy for http and ssh

I'm trying to set up NGINX as a reverse proxy for HTTP and SSL.

Here is a configuration in /etc/nginx/conf.d/default.conf:

upstream sample-client {
  server sample-client:3006;
}

upstream sample-server {
  server sample-server:3000;
}

upstream ssh {
  server sample-server:22;
}

server {
  listen 80;
       
  location / {
    proxy_pass http://sample-client;
  }

  location /api {
    rewrite /api/(.*) /$1 break;
    proxy_pass http://sample-server;
    client_max_body_size 100M;
    proxy_read_timeout 300;
    proxy_connect_timeout 300;
    proxy_send_timeout 300;
  }
     
  error_page 405 =200 @405; 

  location @405 {
    root /usr/share/nginx/html;
      proxy_pass http://sample-client; 
  }  
}

server {
  listen 22;
  proxy_pass ssh;
}

But it throws the next error:

nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/conf.d/default.conf:60

What's going wrong?

Upvotes: 0

Views: 2941

Answers (1)

Srgrn
Srgrn

Reputation: 1825

proxy_pass directive should be inside location block described in https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

To pass a request to an HTTP proxied server, the proxy_pass directive is specified inside a location .

this means that the second server location must include a location block probably similar to

location / { proxy_pass ssh; }

Upvotes: 0

Related Questions