Some questions about using SSH to establish a tunnel using Nginx Reverse proxy to local.

Source: Internet
Author: User
Recently, I debugged the public account function. when receiving the push, I didn't want to submit it to the server to view the log every time. so I used the reverse proxy of Nginx to forward the requests received by Port 80 on the server to 127.0.0.1: 9000 and then use ssh to build a tunnel to set the server's 9000... I recently debugged the public account function and didn't want to submit it to the server to view the log every time when receiving the push.
Therefore, the server uses the Nginx Reverse proxy to forward the requests received by Port 80 to 127.0.0.1: 9000.
Then, the ssh tunnel is used to map Port 9000 of the server to port 80 of the local development machine.

SSH tunneling references http://my.oschina.net/magicly007/blog/480706

Assume that the external domain name of the server is www.site.com.

The Nginx proxy configuration is roughly as follows:

server {     listen       80;          server_name  www.site.com;     root         /var/www/site/;     charset      utf-8;     access_log  /www/log/nginx/site.access.log  main;     error_log   /www/log/nginx/site.error.log;     location / {         try_files $uri $uri/ /$yii_bootstrap?$query_string;         index  index.php;         proxy_pass http://127.0.0.1:9000;         proxy_set_header Host $host:80;         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header Via "nginx";     }     include     /etc/nginx/php-fpm;}

Use the following command to create an ssh tunnel

ssh -R 9000:localhost:80 root@ServerAddress -N

In this way, the tunnel is successfully established.
When I access www.site.com from my local machine, the server successfully forwarded the request to port 80 of my local localhost.
The problem is that only the content received by the default URL of www.site.com can be successfully forwarded, but cannot be redirected.
If I access the www.site.com/post/page server, the server will not forward but directly parse the response.
Does url redirection require special configuration?

Reply content:

I recently debugged the public account function and didn't want to submit it to the server to view the log every time when receiving the push.
Therefore, the server uses the Nginx Reverse proxy to forward the requests received by Port 80 to 127.0.0.1: 9000.
Then, the ssh tunnel is used to map Port 9000 of the server to port 80 of the local development machine.

SSH tunneling references http://my.oschina.net/magicly007/blog/480706

Assume that the external domain name of the server is www.site.com.

The Nginx proxy configuration is roughly as follows:

server {     listen       80;          server_name  www.site.com;     root         /var/www/site/;     charset      utf-8;     access_log  /www/log/nginx/site.access.log  main;     error_log   /www/log/nginx/site.error.log;     location / {         try_files $uri $uri/ /$yii_bootstrap?$query_string;         index  index.php;         proxy_pass http://127.0.0.1:9000;         proxy_set_header Host $host:80;         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header Via "nginx";     }     include     /etc/nginx/php-fpm;}

Use the following command to create an ssh tunnel

ssh -R 9000:localhost:80 root@ServerAddress -N

In this way, the tunnel is successfully established.
When I access www.site.com from my local machine, the server successfully forwarded the request to port 80 of my local localhost.
The problem is that only the content received by the default URL of www.site.com can be successfully forwarded, but cannot be redirected.
If I access the www.site.com/post/page server, the server will not forward but directly parse the response.
Does url redirection require special configuration?

It should be nginx configuration problems.

Try to remove unnecessary nginx settings, which is the simplest.

server {    listen 80 default_server;    client_max_body_size   10M;    client_body_buffer_size   128k;    server_name $host;    index index.html;    root /website/$host;    location / {    }    location ~ /dev/ {        rewrite /dev/(.*)$ /$1 break;        proxy_pass http://localhost:3000;    }}

This is what I am using, and the situation is normal.

I am skeptical about the impact of php. try to remove it.

It is caused by try_files in nginx.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.