• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Reverse Proxying with Nginx : Basics

By Abhishek Ghosh February 5, 2014 7:44 pm Updated on February 5, 2014

Reverse Proxying with Nginx : Basics

Advertisement

Reverse Proxying with Nginx by Simple Editing of the File /etc/nginx/conf.d/default.conf. Reverse proxies can hide the existence and characteristics of an origin server. Few Basic Stuffs are required to be known for performing the whole work.
We think, it is better to know the basics, at least should be mentioned under separate headers by the tutorial providing websites for wider range of the readers. Unfortunately, most of the Blog websites on Technology are mainly AdSense Generated Money driven, thereby the quality of contents are becoming worser, shorter and too much keyword driven. One can expect, a tutorial on Reverse Proxying with Nginx will start with opening the default.conf file without really communicating with the reader.

 

Reverse Proxying with Nginx : Basics for the Beginners

 

We do not think that all the users searching with Reverse Proxying with Nginx has enough good knowledge on basics. It is good to have idea about SOCKS Protocol and Proxy, Proxy and Proxy Server, some idea on nginx HTTP Server.

As far with ngnix part only; we have some related tutorials like Installing nginx on Rackspace Cloud Server Video, Shifting WordPress From Apache to nginx Web Server, Installing Nginx With PHP5, MySQL on Rackspace Cloud Server, Install nginx on Rackspace Cloud Server with Centmin Mod Nginx Auto Installer or Proxy related guide – How to Use Rackspace Cloud Server as Own Proxy.

Advertisement

---

Obviously there will be readers who are more knowledgeable about ngnix administration but might not be aware about this particular topic.

The reverse proxy is a proxy, where the resources for a client of one or more servers becomes obsolete. The address translation is performed in the opposite direction, whereby the true address of the target system is hidden from the client. During a typical proxy multiple clients can be used for to an internal (private – self-contained) to an external resource to grant access; a reverse proxy works in the other way.

Reverse Proxying with Nginx

The reverse proxy initially offer the same functionality as port forwarding and so it allows to externally connect to a behind the relay server on the internal network. The reverse proxy can distribute the load across multiple servers. In web server, the reverse proxy URLs may need to be rewritten in every web page. Reverse proxies can perform A/B testing and multivariate testing without placing javascript tags or code into pages.

 

Reverse Proxying with Nginx

 

Minimum two servers are required, take that the main domain resolves example.com and the other server resolves reverse.example.com ; both points to publicly available IP addresses.

Official guide can be found here :

Vim
1
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

Ubuntu also has helpful resource :

Vim
1
https://help.ubuntu.com/community/Nginx/ReverseProxy

We will build from noarch source :

Vim
1
http://www.redhat.com/archives/shrike-list/2003-April/msg00504.html

Manually point your browser towards :

Vim
1
http://nginx.org/packages/rhel/6/noarch/RPMS/

to check if any update is available, the command below is for the current version (and you might be reading after 3 years). We need to wget it and build :

Vim
1
2
3
4
# Step 1
wget http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
# Step 2
rpm -iv nginx-release-rhel-6-0.el6.ngx.noarch.rpm

and install it :

Vim
1
yum install nginx

The configuring part is important, we are editing with command line Vim (vi) text editor, one can use nano. Open the default.conf file :

Vim
1
vi /etc/nginx/conf.d/default.conf

A typical example is provided here :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## Basic reverse proxy server ##
## Apache (vm02) backend for www.example.com ##
upstream apachephp  {
      server 192.168.1.11:80; #Apache1
}
## Lighttpd (vm01) backend for reverse.example.com ##
upstream lighttpd  {
      server ANY_IP:80; #Lighttpd1
}
## Start example.com ##
server {
    listen       ANY_IP:80;
    server_name  example.com;
    access_log  /var/log/nginx/log/example.access.log  main;
    error_log  /var/log/nginx/log/example.error.log;
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    ## send request back to apache1 ##
    location / {
     proxy_pass  http://apachephp;
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_redirect off;
     proxy_buffering off;
     proxy_set_header        Host            $host;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}
## End example.com ##
## START reverse.example.com ##
server {
   listen      OTHER_IP:80;
   server_name reverse.example.com;
   access_log  /var/log/nginx/log/reverse.example.com.access.log  main;
   error_log   /var/log/nginx/log/reverse.example.com.error.log;
   root        /usr/local/nginx/html;
   index       index.html;
   location / {
        proxy_pass  http://lighttpd;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header        Host            reverse.example.com;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
## END reverse.example.com  ##

Configuring firewall is not described here. This part is important but is dependent on the infrastructure. On KVM virtualization, we usually open only the ports 80 and 443 on eth0 and set eth1 as trusted device.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Reverse Proxying with Nginx : Basics

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

  • How To Configure Nginx Access Log With GeoIP (Ubuntu 16.04)

    Here is How To Configure Nginx Access Log With GeoIP on Ubuntu 16.04. Usage Commands Also Shown. Access Log is Powerful & Configurable Tool.

  • Join/Merge Multiple Log Files For Big Data Analysis

    Here Are The Ways To Join/Merge Multiple Log Files For Big Data Analysis, Store Them To OpenStack Based Cloud Storage And Delete Old Files.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy