因为gotty我做了url加密,html
因此url在nginx里的前缀要能替换才行。nginx
配置关键就在于有没有/git
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream k8s_gotty_log { ip_hash; server 1.2.3.4:8081; } upstream k8s_gotty_tty { ip_hash; server 1.2.3.4:8082; } server { listen 8080; server_name localhost; client_max_body_size 500m; proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600; # add_header 'Access-Control-Allow-Origin' '*'; # proxy_set_header Connection ""; proxy_http_version 1.1; proxy_set_header Origin ""; proxy_set_header Host $host; proxy_set_header X-Real-Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; location /k8s_gotty_log/ { proxy_pass http://k8s_gotty_log/; } location /k8s_gotty_tty/ { proxy_pass http://k8s_gotty_tty/; } } }
其中涉及两个知识点,标红的。github
1,在Nginx反向代理一个带有WebSocket功能的程序时,发现访问WebSocket接口时老是出现403响应。app
查询相关解决办法,找到github上的这个issue,因此只须要修改Nginx的配置,添加proxy_set_header Origin "";
就好了:加密
2,在nginx中配置proxy_pass时,当在后面的url加上了/,至关因而绝对根路径,则nginx不会把location中匹配的路径部分代理走;若是没有/,则会把匹配的路径部分也给代理走。url
https://www.jb51.net/article/78746.htmspa
下面四种状况分别用http://192.168.1.4/proxy/test.html 进行访问。
第一种:.net
会被代理到http://127.0.0.1:81/test.html 这个url
第二咱(相对于第一种,最后少一个 /)代理
会被代理到http://127.0.0.1:81/proxy/test.html 这个url
第三种:
会被代理到http://127.0.0.1:81/ftlynx/test.html 这个url。
第四种状况(相对于第三种,最后少一个 / ):
会被代理到http://127.0.0.1:81/ftlynxtest.html 这个url