【问题标题】:NGINX as reverse proxy for http and sshNGINX 作为 http 和 ssh 的反向代理
【发布时间】:2021-07-18 09:41:37
【问题描述】:

我正在尝试将 NGINX 设置为 HTTP 和 SSL 的反向代理。

这是/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;
}

但它会引发下一个错误:

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

怎么了?

【问题讨论】:

标签: nginx ssh reverse-proxy


【解决方案1】:

proxy_pass 指令应该在位置块内 描述于https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

要将请求传递给 HTTP 代理服务器, proxy_pass 指令在内部指定 location.

这意味着第二个服务器位置必须包含一个位置块 可能类似于

位置/{ proxy_pass ssh; }

【讨论】:

    猜你喜欢
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 2017-06-29
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多