Sometimes, to access some programs or servers we need to add a port number to the end of IP or domain. And it is really annoying to have a link like example.com:3000. So, in case you want to avoid typing a port number, we will need to set up a proxy. If someone doesn’t know what proxy is, I will just say “It helps you to avoid typing additional things into your domain”. Now let’s get started!

I will show you on both popular web servers Apache and NGINX.

Apache

1 step: Creating configuration file

First, go to /etc/apache2/sites-available and create a file your-site-name.conf (filename is optional, you can name it however you want). Then add text below (don’t forget to change some information in) and save your file.

<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/example/
ProxyPassReverse / http://localhost:8080/example/
</VirtualHost>

2 step: Enabling the configuration

So, after creating the file we would need to enable a proxy plugin on Apache. To do that type sudo a2enmod mod_proxy. Then we need to enable our configuration sudo a2ensite your-site-name.conf and reboot Apache using sudo systemctl reboot apache2.

This is it, now you can test your configuration.

NGINX

1 step: Creating a configuration file

First of all, go to /etc/nginx/sites-available and then create file your-site-name (filename is optional, you can name it however you want and it has no extension). Open the file and add text below (don’t forget to change some information in) then save your file and close it.

server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
}
}

2 step: Enabling our configuration

After creating the file run sudo ln -s /etc/nginx/sites-available/your-site-name /etc/nginx/sites-enabled/  to create a link in sites-enabled (to activate your configuration) and then reboot your NGINX with sudo systemctl reboot nginx.

This is it, now you can test your configuration.

Conclusion

So, now you have a configuration to pass the proxy. If you have any problems or questions please leave a comment under this post.

Happy coding!

Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.