Windows下使用nginx搭建反向 Proxy伺服器

來源:互聯網
上載者:User

標籤:mime   for   ssi   erer   eal   從伺服器   detail   worker   nobody   

    反向 Proxy(Reverse Proxy)方式是指以Proxy 伺服器來接受internet上的串連請求,然後將請求轉寄給內部網路上的伺服器,並將從伺服器上得到的結果返回給internet上請求串連的用戶端,此時Proxy 伺服器對外就表現為一個反向 Proxy伺服器。

    本文意在搭建一台nginx反向 Proxy伺服器。

1、nginx的安裝配置可參考博文:http://www.cnblogs.com/wangwust/p/6420503.html

2、修改nginx的設定檔,如下:

server {        listen       8888;        server_name  localhost;}

   修改為:

server {        listen          80;        server_name     192.168.1.20;    //反向 Proxy伺服器IP        location / {                proxy_pass              http://192.168.1.10;     //web伺服器IP                proxy_redirect          off;                proxy_set_header        X-Real-IP       $remote_addr;                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;}

3、驗證。在瀏覽器中訪問192.168.1.20,看看處理請求的是不是192.168.1.10。

4、參考配置:

#user  nobody;worker_processes  4;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘    #                  ‘$status $body_bytes_sent "$http_referer" ‘    #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {        listen       8081;        server_name  www.test.com;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            root   D:/work/temp/NginxTest;            index  index.html index.htm;        }                location ^~ /kuaixun/ {            proxy_pass http://localhost/kuaixun/;            proxy_redirect off;             proxy_set_header Host $host:$server_port;              proxy_set_header X-Real-IP $remote_addr;              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;          }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #location ~ \.php$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}        # deny access to .htaccess files, if Apache‘s document root        # concurs with nginx‘s one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #    #server {    #    listen       443 ssl;    #    server_name  localhost;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_cache    shared:SSL:1m;    #    ssl_session_timeout  5m;    #    ssl_ciphers  HIGH:!aNULL:!MD5;    #    ssl_prefer_server_ciphers  on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}

 

本文參考:http://blog.csdn.net/abc19900828/article/details/39478125。

Windows下使用nginx搭建反向 Proxy伺服器

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.