User Tools

Site Tools


nginx:restrict_nginx_to_the_private_network

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
nginx:restrict_nginx_to_the_private_network [2019/12/01 10:42] – removed peternginx:restrict_nginx_to_the_private_network [2020/07/26 23:50] (current) – old revision restored (2016/10/07 17:00) 192.99.15.29
Line 1: Line 1:
 +====== NginX - Restrict Nginx to the Private Network ======
 +
 +<code bash>
 +sudo vi /etc/nginx/sites-enabled/default
 +</code>
 +
 +Inside, find the **listen** directive. You should find it twice in a row towards the top of the configuration:
 +
 +<file /etc/nginx/sites-enabled/default>
 +server {
 +    listen 80 default_server;
 +    listen [::]:80 default_server ipv6only=on;
 +
 +    . . .
 +}
 +</file>
 +
 +At the first listen directive, add your web server's private IP address and a colon just ahead of the 80 to tell Nginx to only listen on the private interface. We are only demonstrating IPv4 forwarding in this guide, so we can remove the second listen directive, which is configured for IPv6.
 +
 +In our example, we'd modify the listen directives to look like this:
 +
 +<file /etc/nginx/sites-enabled/default>
 +server {
 +    listen 192.0.2.2:80 default_server;
 +
 +    . . .
 +}
 +</file>
 +
 +Save and close the file when you are finished. Test the file for syntax errors by typing:
 +
 +<code bash>
 +sudo nginx -t
 +</code>
 +
 +If no errors are shown, restart Nginx to enable the new configuration:
 +
 +<code bash>
 +sudo service nginx restart
 +</code>
  
nginx/restrict_nginx_to_the_private_network.1575196956.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki