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

Source: Internet
Author: User
Tags nginx reverse proxy
Recently debug public number function, do not want to submit to the server every time to read the log
So on the server with the Nginx reverse proxy to the server 80 port received the request forwarded to the 127.0.0.1:9000
Then using SSH to tunnel the server 9000 port mapped to my local development machine 80

SSH Tunnel Reference http://my.oschina.net/magicly007/blog/480706

Assume server external domain name 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

So that the tunnel was built successfully.
The server successfully forwarded the request to the 80 port of my native localhost when I visited www.site.com on the local machine.
The problem is that you can only successfully forward www.site.com's default URL received content but not redirect
Suppose I access the Www.site.com/post/page server and I do not forward it but parse the response directly.
Does URL redirection need special configuration, please?

Reply content:

Recently debug public number function, do not want to submit to the server every time to read the log
So on the server with the Nginx reverse proxy to the server 80 port received the request forwarded to the 127.0.0.1:9000
Then using SSH to tunnel the server 9000 port mapped to my local development machine 80

SSH Tunnel Reference http://my.oschina.net/magicly007/blog/480706

Assume server external domain name 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

So that the tunnel was built successfully.
The server successfully forwarded the request to the 80 port of my native localhost when I visited www.site.com on the local machine.
The problem is that you can only successfully forward www.site.com's default URL received content but not redirect
Suppose I access the Www.site.com/post/page server and I do not forward it but parse the response directly.
Does URL redirection need special configuration, please?

It should be an nginx configuration problem.

Try removing the Nginx extra settings, using only 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, the situation is normal.

Personal doubts about the impact of PHP, try to remove it.

It was the try_files in Nginx that caused it to be deleted.

  • 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.