How to Setup a Reverse Proxy With Nginx on Centos 7

First off, install nginx on the server machine.

1yum update
2yum install epel-release
3yum install nginx

Edit the nginx config file then.

1cd /etc/nginx/nginx.conf
2vim nginx.conf

Edit the file like this:

1server_name domain.com;

If you are not going to use domain name, a public ip address would also work instead of domain.com πŸ™‚
Find location section in the file and replace it with:

1location / {
2  proxy_pass http://server_ip:8080;
3  proxy_http_version 1.1;
4  proxy_set_header Upgrade $http_upgrade;
5  proxy_set_header Connection 'upgrade';
6  proxy_set_header Host $host;
7  proxy_cache_bypass $http_upgrade;
8}

Boom! You did it!
You can also add another app in the same nginx server block, for example, location /app_name { … … }, which means that server relays from the route /app_name, and another port, of course.
Last but not least, don’t forget to check the server's selinux settings.

1getsebool -a
2setsebool -P configuration_name on

Happy networking gents. πŸ™‚

comments powered by Disqus