V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
yeccc
V2EX  ›  NGINX

大佬们求助 nginx 配置

  •  
  •   yeccc · 310 天前 · 1406 次点击
    这是一个创建于 310 天前的主题,其中的信息可能已经有所发展或是发生改变。

    公司业务每次更新测试代码都需要登陆到跳板机,在跳板机更新代码打包然后在远程内网的服务器手动将包放上去发布,跳板机器是可以访问代码仓库云效的, 所以在跳板机搞了一个 nginx 来做正向代理处理内网服务器的请求来实现代码更新包更新之类的操作,但是不知道是不是配置的问题一直请求一直 405 ,还有更新 mavne 依赖的时候也会 timeou t 前端 node 依赖也是安装不了的 image.png

    image.png

    ,http 是可以正常拉取代码的但是 https 就不行,求大佬帮忙看看 下面是 nginx 配置(添加了 ngx_http_proxy_connect 模块)

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
    server {
        resolver 114.114.114.114;
        listen       880 default_server;
        location / {
            proxy_pass http://$host$request_uri;     
                    proxy_set_header HOST $host;
                    proxy_buffers 256 4k;
                    proxy_max_temp_file_size 0k;
                    proxy_connect_timeout 30;
                    proxy_send_timeout 60;
                    proxy_read_timeout 60;
                    proxy_next_upstream error timeout invalid_header http_502;
        }
    }
    server {
         listen  443;
         # dns resolver used by forward proxying
         resolver  8.8.8.8;
    
         # forward proxy for CONNECT request
         proxy_connect;
         proxy_connect_allow            443;
         proxy_connect_connect_timeout  10s;
         proxy_connect_read_timeout     10s;
         proxy_connect_send_timeout     10s;
    
         # forward proxy for non-CONNECT request
         location / {
                proxy_set_header Host $host;
                proxy_pass $scheme://$host$request_uri;
         }
     }
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }
    
    
    7 条回复    2023-06-24 15:32:55 +08:00
    ryd994
        1
    ryd994  
       310 天前 via Android
    你不需要 listen 443

    proxy_connect 相关内容放到上面 880 的配置一起

    代理 https 时,客户端会明文连接到代理服务器,要求 connect 某网站。代理服务器会通过明文通道直接转发 TLS 加密后的密文。TLS 的安全性是从后端到客户端,端到端加密。代理服务器不解密。
    akira
        2
    akira  
       309 天前
    有点奇怪的用法。。
    yeccc
        3
    yeccc  
    OP
       309 天前
    @akira 为了不手动打包不得已
    yeccc
        4
    yeccc  
    OP
       309 天前
    @ryd994 哦哦,谢谢大佬我去试试
    yeccc
        5
    yeccc  
    OP
       309 天前
    @ryd994 大佬我按照你说的将 proxy_connect 与 880 的配置在一起,还是一样的问题
    http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    server {
    resolver 8.8.8.8; #指定 DNS 服务器 IP 地址
    listen 880 default_server;

    proxy_connect;
    proxy_connect_allow 443;
    proxy_connect_connect_timeout 10s;
    proxy_connect_read_timeout 10s;
    proxy_connect_send_timeout 10s;

    location / {
    proxy_pass $scheme://$host$request_uri; #设定代理服务器的协议和地址
    proxy_set_header HOST $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_buffers 256 4k;
    proxy_max_temp_file_size 0k;
    proxy_connect_timeout 30;
    proxy_send_timeout 60;
    proxy_read_timeout 60;
    proxy_next_upstream error timeout invalid_header http_502;
    error_page 405 =200 http://$host$request_uri;
    }
    }
    julyclyde
        6
    julyclyde  
       308 天前
    405 是 method not allowed
    你的代理服务器环境变量咋设置的?是不是匹配到另一个 server{}去了?
    看看 nginx 的 error_log 里咋写的
    yeccc
        7
    yeccc  
    OP
       308 天前
    @julyclyde 改了源码,重新编译了一下可以了谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2682 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:51 · PVG 18:51 · LAX 03:51 · JFK 06:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.