• Welcome to Web Hosting Community Forum for Webmasters - Web hosting Forum.
 

Recommended Providers

Fully Managed WordPress Hosting
lc_banner_leadgen_3
Fully Managed WordPress Hosting

WordPress Theme

Divi WordPress Theme
WPZOOM

Forum Membership

Forum Membership

Prevent direct access to specific port with nginx as reverse proxy and htaccess

Started by Chris, March 21, 2017, 05:02:24 PM

Chris

Hello all,

I have a website running well, listening on port 8069 (let's say mywebsite DOT com:8069)

I'd like to prevent users from accessing it directly with an htaccess for instance.

For some reason (it's an Odoo python script listening on this port), I can't directly use an htaccess file so I would like to use nginx as a reverse proxy :

[users] <---> my-nginx-proxy DOT com:80 <----> /mywebsite DOT com:8069

Is it possible to filter direct traffic on port 8069 with iptables on mywebsite.com AND allow indirect traffic from nginx reverse proxy ?
If so, how ? Since I shall then just use an htaccess on my-nginx-proxy.com

Thanks for your help

Kailash

Yes, you would use a standard nginx reverse proxy via a server + location blocks with a proxy_pass:

server {
   listen Your_SERVER_IP:80
   server_name my-nginx-proxy.com

    location /
    {
        proxy_pass https://YOUR_IP_HERE-OR-127.0.0.1:8069;
        .... any additional proxy_ directives like setting headers for the host.
    }
}


You can also add http authentication options or deny / allow for specific IPs or ranges. Then in iptables, restrict direct access via rules for the specific ips that you want to access it.