Configuring Nginx Reverse Proxy In Ubuntu

Nginx runs on port no. 80 by default and its working directory is in /etc/nginx to go to working directory in nginx execute below command:-

cd /etc/nginx

Here it will list all the files and directories that are related to nginx, here two directories i.e sites-available and sites-enabled are most important part of nginx which consists of default configuration file related to nginx

Let’s have a look on default configuration file in sites-available

If you want to do some modifications for reverse proxy then you can edit your default configuration file or else create new one, for this demo purpose we will be editing our default configuration for creating new one copy the below code and paste it in your sites-available and do not forget to replace the server name.

server {
	listen 80;
	server_name _;
	location / {
			proxy_pass http://localhost:<your-port-no>;

If you are creating new configuration then you have to create a link to make your file link to sites-enabled directory. For creating the soft link execute the below command

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

For the demo purpose we will be editing the default configuration, in which we will be doing proxy pass on portno. 8080 on which we are running jenkins, for knowing about jenkins pls visit the jenkins section in learn devops on salesforcedrillers,

As shown in above screenshot we are doing proxy pass on portno. 8080.

Once you are done with your configuration, test your configuration by executing

sudo nginx -t

If you see some failure over here it means that your configuration is not correct, then refer back to your configuration and correct it

Once it’s done then restart your nginx configuration by executing

sudo service nginx restart

Now hit your server ip on the browser now instead of nginx welcome page you will see your application which is jenkins in our demo case

Subscribe Now