nginx反代ngrok的问题

发布于 2022-09-02 00:42:39 字数 2271 浏览 23 评论 0

我的机器上部署了nginx与ngrok但是我需要让两个程序都使用80和443
我现在ngrok监听81,444然后nginx反代

反代配置如下

server {    
    listen  80;  
    server_name *.0n0.win;  
      
    root   html;
    index  index.html index.htm index.php;
 
    ## send request back to apache ##
    location / {
        proxy_pass  http://127.0.0.1:81;
        #Proxy Settings
        proxy_redirect     off;
        #proxy_set_header Host downloads.openwrt.org;
        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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }
}  

server {
    listen 443;
    server_name *.0n0.win;
 
    ssl on;
    ssl_certificate /etc/letsencrypt/live/shirakun.cc/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/shirakun.cc/privkey.pem;
#    access_log  logs/quancha.access.log  main;
#    error_log  logs/quancha.error.log;
    root   html;
    index  index.html index.htm index.php;
 
    ## send request back to apache ##
    location / {
        proxy_pass  https://127.0.0.1:444;
        #Proxy Settings
        proxy_redirect     off;
        #proxy_set_header Host downloads.openwrt.org;
        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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }
}

但是,现在出现一个问题,我映射后直接访问仍提示隧道未映射,然后还是得在域名后面加上:81才能访问,请问如何解决

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟酒忠诚 2022-09-09 00:42:39
server {    
    listen  80;  
    server_name *.0n0.win;  
      
    root   html;
    index  index.html index.htm index.php;
 
    ## send request back to apache ##
    location / {
        proxy_pass  http://127.0.0.1:81;
        #Proxy Settings
        proxy_redirect     off;
        #proxy_set_header Host downloads.openwrt.org;
        proxy_set_header   Host             $host:81;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }
}  

server {
    listen 443;
    server_name *.0n0.win;
 
    ssl on;
    ssl_certificate /etc/letsencrypt/live/shirakun.cc/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/shirakun.cc/privkey.pem;
#    access_log  logs/quancha.access.log  main;
#    error_log  logs/quancha.error.log;
    root   html;
    index  index.html index.htm index.php;
 
    ## send request back to apache ##
    location / {
        proxy_pass  https://127.0.0.1:444;
        #Proxy Settings
        proxy_redirect     off;
        #proxy_set_header Host downloads.openwrt.org;
        proxy_set_header   Host             $host:444;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }
}
单身情人 2022-09-09 00:42:39

我也被这个问题坑到了。

解决方法就是注释掉

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

这行。

如果nginx反代的同时又转发了真实的IP地址,ngrok会收到两个ip导致冲突。

计㈡愣 2022-09-09 00:42:39

国内最大nat技术交流社区里有很多资源 http://natforum.com

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文