Configuring Nginx
This section is to configure Nginx as a reverse proxy server
in a Linux machine.
Step 1: Go to the /etc/nginx/ folder and open the nginx.conf
file in a text editor.
Step 2: Locate the “server” block and add another “server”
block as shown below.
This is to configure Nginx as a reverse proxy server which
will redirect requests made to the URL: https://172.16.100.51:8080/
to the PowerServer Web APIs running on Kestrel at
https://172.16.100.35:6000/.
|
1 2 3 4 5 6 7 |
server { listen 8080; location / { proxy_set_header Host $http_host; proxy_pass https://172.16.100.35:6000; } } |
Tip: In CentOS, you can
execute the command “netstat -anp | grep 8080” to check if the port
number is occupied by any other program.
Step 3: Run the following command to add port 8080 to
“http_port_t”:
|
1 |
$ sudo semanage port -a -t http_port_t -p tcp 8080 |
Note
If the port is not properly added, you may see the following
error when Nginx starts:

and may have the following error in the
varlog
ginxerror.log file.
|
1 |
2021/06/09 05:26:29 [emerg] 4107#0: bind() to 0.0.0.0:8080 failed (13: Permission denied) |
Step 4: If you have set up a firewall on the server, run the
following command to permanently enable port 8080:
|
1 |
$ sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp |
and the following command to reload the firewall
service:
|
1 |
$ sudo firewall-cmd --reload |
Note
If the firewall blocks the port number, you will have the
following error when running the application.

Step 5: Check if any syntax errors in the Nginx configuration
file, and then restart Nginx for the changes to take effect.
|
1 |
$ sudo nginx -t |
|
1 |
$ sudo systemctl restart nginx |
Step 6: Verify that Nginx is running.
|
1 |
$ sudo systemctl status nginx |
Step 7: Run the following command to allow Nginx to make
outbound connections.
|
1 |
$ sudo setsebool -P httpd_can_network_connect 1 |
Note
If Nginx is not allowed to make outbound connections, you
may encounter the following error when running the
application,

and may have the following errors in the
varlog
ginxerror.log file.
|
1 2 |
2021/06/09 02:38:02 [crit] 5364#0: *2 connect() to 172.16.100.35:6000 failed (13: Permission denied) while connecting to upstream, client: 172.16.100.35, server: _, request: "POST /api/ServerApi/CreateSession HTTP/1.1", upstream: "http://172.16.100.35:6000/api/ServerApi/CreateSession", host: "172.16.100.51" |