Nginx Building Reverse Proxy Server process details-Windows

Source: Internet
Author: User

This article is mainly nginx to do a simple reverse server proxy and static file caching.

The reverse proxy is a proxy server that accepts connection requests on the Internet and then forwards the requests to the servers on the internal network (Reverse proxies). and returns the results from the server to the client requesting a connection on the Internet, when the proxy server appears as a server externally

Let's get started.

1. Vistudio created two simple WebApplication (Web Forms), one called WebApplication1, one called WebApplication2. To differentiate two applications, make some changes to the default page to identify.

For example, add application one, application, and so on.

2. Publish two projects, and then IIS add two sites, with 8050,8060 for each port.

3. Test site, input http://localhost:8050,http://localhost:8060, all can be accessed normally

4. Download the installation Nginx, referring to the previous article, I am listening here is 2016 port

5. Locate the c:\nginx-1.9.9\conf\nginx.conf file and modify the following

#user nobody;worker_processes 1;error_log logs/error.log;error_log logs/error.log notice;error_log logs/error.log I NFO; #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;upstream windowsapp.com{server 127.0.0.1:8050 weight=1; Server 127.0.0.1:8060 weight=1;        } server {Listen 2016;        server_name localhost;        #charset Koi8-r;        #access_log Logs/host.access.log Main;        #location/{# root HTML;        # index index.html index.htm;          #} #error_page 404    /404.html;        # REDIRECT Server error pages to the static page/50x.html # Error_page 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$ {# ProX        Y_pass http://127.0.0.1; #}location/{Proxy_pass http://windowsapp.com;} Location ~ \.        (CSS) $ {root/nginx-1.9.9/staticfiles/;   Expires 7d; }location ~ \.       (JS) $ {root/nginx-1.9.9/staticfiles/;    Expires 7d;        # 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; #    }    #}}

Focus Point:

1. HTTP under server listen configured to 2016, indicates listening 2016 port

2. Upstream cluster, which needs to be configured outside of the server in HTTP, that is, the same level as the server

    upstream windowsapp.com{        127.0.  0.1:8050 weight=1;         127.0. 0.1:8060 weight=1;     }

3. Location Configuration Proxy

    Location/ {        proxy_pass http:///windowsapp.com;    }

At this time, you visit http://localhost:2016, sometimes access is 8050, sometimes 8060 of the site.

You may have to restart after you have modified the Conf file, open cmd

CD c:\nginx-1.9.9

Nginx-s Reload

It's OK to finish the execution.

Static file Cache configuration

1. Copy CSS and JS and images to C:\nginx-1.9.9\staticfiles

2. In the sever, add the following configuration, restart Nginx, please note that the following is root,

In other words, Scripts/jquery.js will ask for/nginx-1.9.9/staticfiles/scripts/jquery.js, Pro, careful oh.

You can easily modify, configure a wrong, you will find that JS and CSS will not be requested.

    Location ~ \. ( CSS) $ {        /nginx-1.9.  9/staticfiles/;                Expires 7d;                   }     ~ \. (JS) $ {        /nginx-1.9.  9/staticfiles/;               Expires 7d;                }

At this point, you have already cached JS and CSS files, the time is 7d.

Reference:

Nginx Building Reverse Proxy Server process detailed: http://www.open-open.com/lib/view/open1417488526633.html

Nginx static file Processing: http://m.blog.csdn.net/blog/kun20031029/25398049

Simple Load balancing:https://www.nginx.com/resources/wiki/start/topics/examples/loadbalanceexample/

Nginx Cluster Newspaper "upstream" directive is isn't allowed here error:

http://www.jiucool.org/blog/nginx-cluster-reported-upstream-directive-is-not-allowed-here-error/

Nginx Building Reverse Proxy Server process details-Windows

Related Article

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.