Nginx is a free and open-source web server and It works quite well as a reverse proxy server by directing web traffic to specific servers. This blog will show you how to configure Nginx on a Ubuntu VM and we will use this to configure an Nginx Reverse proxy required for our vCD
Step 1: Download and Install Ubuntu OS
Once installed, launch an SSH session
Step 2: Update Ubuntu Software Repositories
To ensure we always get the latest patch and security updates possible. We do that by running a command
sudo apt-get update
Step 3: Install Nginx
sudo apt-get install nginx -y
Step 4: Enable Nginx Services
# To Manage Nginx deamon
# systemctl start|stop|status nginx
# To Stop and Disable Service
systemctl enable |disable nginx
# To Ensure service stays peristant during reboots
chkconfig nginx on
# To Show status of httpd
systemctl list-unit-files | grep nginx
Optionally, services can be restarted as
/etc/init.d/nginx | stop | start
Step 6: Generate Cert files
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/ vcloud..key -out /etc/nginx/ssl/ vcloud.crt
Step 5: Create New Configuration File
To create a new configuration file, enter:
vi /etc/nginx/conf.d/vcloud.conf
server {
listen 443;
# SSL Config
ssl_certifcate /etc/nginx/ssl/vcloud.crt
ssl_certificate_key /etc/ssl/vcloud.key
location / {
proxy_pass http://my_server; # vCD cell webconsole
}
}
server {
listen 8443;
location / {
proxy_pass http://my_server:8443; # vCD cell console proxy
}
}
This is a very basic Nginx reverse proxy example. Nginx is set to listen for all traffic on port 80 for all traffic.
The proxy_pass
command directs all traffic on port 80 to http://my_server
. Just change http://my_server
to the location of your choice, and Nginx will intercept client requests and route them to the location you specify
To activate the new Nginx file, enter:
ln -s /etc/nginx/sites-available/custom_server.conf /etc/nginx/sites-enabled/custom_server.conf
Step 7: Test and Restart Nginx
To test Nginx:
nginx -t
To restart Nginx:
systemctl nginx restart