如何解决NGINX 作为 http 和 ssh 的反向代理
我正在尝试将 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
怎么了?
解决方法
proxy_pass 指令应该在位置块内 https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
中描述要将请求传递到 HTTP 代理服务器,
proxy_pass
指令在一个
location
.
这意味着第二个服务器位置必须包含一个位置块 大概类似于
位置 / { proxy_pass SSH; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。