Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Apache/Nginx ReverseProxy Proxy

11 Oct 2020 » web

Nginx

# Proxy

server {
    listen 80;
    
    proxy_ssl_server_name on;
    location /prod {
        proxy_pass <endpoint>;
    }
    location /dev {
       proxy_pass <endpoint>; 
    }
}


# Reverse Proxy

server {
    listen 80;
    
    server_name <cname>.<domain>;
    location / {
        proxy_pass <endpoint>
    }
    location /user {
        rewrite /user/(.*) $1 break;
        proxy_pass <endpoint>;
    }
}

Apache


# Proxy
<VirtualHost *:80>
    ServerName "hostname"
    ProxyRequests On

    ProxyPassMatch   ^/suffix/(.*) http://localhost:port/$1
    ProxyPassReverse ^/suffix/(.*) http://localhost:port/$1
    
    <Location "/prod">
       ProxyPass <endpoint>
       ProxyPassReverse <endpoint>
    </Location>
    <Location "/dev">
       ProxyPass <endpoint>
       ProxyPassReverse <endpoint>
    </Location>
</VirtualHost>


# Reverse Proxy
<VirtualHost *:80>
    ServerName "cname.domain.com"
    ServerAlias "cname.domain2.com"
    
    ProxyPassMatch ^/(.*)$ <endpoint>/$1
    ProxyPassReverse ^/(.*)$ <endpoint>/$1
</VirtualHost>