【发布时间】: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
怎么了?
【问题讨论】:
-
要为 ssh 执行 proxy_pass,您需要使用 stream 模块而不是 http 模块。否则,配置将与尝试代理 http 流量时相同。 nginx.org/en/docs/stream/ngx_stream_proxy_module.html
标签: nginx ssh reverse-proxy