Over a million developers have joined DZone.

Virtual Hosting Using Nginx Server

Let's see how to configure Nginx as a reverse proxy/virtual hosting purpose.

· Performance Zone

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Nginx is a web server, which can also act as a reverse proxy, HTTP server, IMAP/POP3 proxy server as well as a load balancer. It is well known for its stability, high-performance, simple configuration, rich feature set, and low resource consumption. So, we can deploy our web applications like HTML pages and PHP-related applications into this server directly.

Let's See How to Configure the Nginx as a Reverse Proxy/Virtual Hosting Purpose

#1. Deploy the nginx application in any server (I am taking Ubuntu System).

#2. Choose any domain/sub-domain name, and do the C-name configuring that domain name to nginx server (Ubuntu System Port 80).

Note: Port 80 is the default port for nginx. If you change the port, you need to map the C-name according to that.

#3. Once C-name and nginx applications are ready, create a conf.d folder inside the nginx.

#4. Create a configuration file with the name of domain/sub-domain along with the .conf extension.

For example, if you want the application should work on ‘abc.mycompany.com,’ you have to create a configuration file with the name of ‘abc.mycompany.com.conf,’ and copy the below-given code and save the file.

 server {

      listen 80;

      server_name abc.mycompany.com;

   location / {

      proxy_pass http://10.10.10.10:portnumber/;

      proxy_http_version 1.1;

      proxy_read_timeout 300000;

      proxy_set_header Upgrade $http_upgrade;

      proxy_set_header Connection 'upgrade';

      proxy_set_header Host $host;

      proxy_cache_bypass $http_upgrade;

     }

   }

#5. Restart/reload the Nginx.

Now your application will work with the domain name based on your configuration.


Glossary

Listen Nginx port listener

Server_name – Domain name

Proxy_pass – Actual running application URL (domain name indirectly calls this URL)

Proxy_read_timeout – For long connection establishment (optional)

Nginx default connection timeout – 600 m.sec

Learn tips and best practices for optimizing your capacity management strategy with the Market Guide for Capacity Management, brought to you in partnership with BMC.

Topics:
http ,http server ,html ,php ,ubuntu ,virtual applications ,html doctype ,web server ,server ,proxy

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}