nginx本地端口转发

1、安装Nginx,apt-get install nginx

2、建立站点:

测试:

创建一个8000端口的服务器:

vim /etc/nginx/conf.d/site8000.conf

server {
        listen          8000;
        server_name     ~^\d+\.\d+\.\d+\.\d+$;
        #charset koi8-r;
        error_page  404  /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 503 504  /50x.html;
        error_log       /var/log/nginx/debug.log debug;
        index   index.html index.htm;
        root /var/www/html/8000/;
}

 

创建一个80端口转发到8000的配置文件:

vim /etc/nginx/conf.d/site80-8000.conf

server {
        listen          80;
        server_name     ~^\d+\.\d+\.\d+\.\d+$;
        #charset koi8-r;
        error_page  404  /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 503 504  /50x.html;
        error_log       /var/log/nginx/debug.log debug;
        index   index.html index.htm;

        location / {
        proxy_pass http://zhangqing.com:8000/;
        proxy_set_header Host $host:8000;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

 

发表评论

207 次浏览