search

Home  >  Q&A  >  body text

Problem with nginx regeneration ngrok

I have nginx and ngrok deployed on my machine, but I need both programs to use 80 and 443
Now ngrok listens to 81, 444 and then nginx reverses generation

The anti-generation configuration is as follows

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;
   }
}

However, there is a problem now. After mapping, I still get the message that the tunnel is not mapped when accessing it directly. Then I still have to add: 81 after the domain name to access it. How to solve it?

ringa_leeringa_lee2758 days ago931

reply all(3)I'll reply

  • 某草草

    某草草2017-05-16 17:21:30

    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;
       }
    }

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 17:21:30

    I was also stumped by this problem.

    The solution is to comment out

    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    This is OK.

    If nginx reverses generation and forwards the real IP address at the same time, ngrok will receive two IPs and cause a conflict.

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-16 17:21:30

    There are many resources in the largest nat technology exchange community in China http://natforum.com

    reply
    0
  • Cancelreply