Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache: Using reverse proxy and run local website

On my linux machine I have apache2 running as a reverse proxy, because I wanted to make another webserver on port 8083 accessible while also making it password protected. For this I added this to my apache2.conf:

<VirtualHost *:80> 
   <Location / >
       AuthName "Protected Area"
       AuthType Basic
       AuthUserFile /home/pi/.htpasswd
       Require valid-user 
   </Location>
      ProxyPass / http://localhost:8083/
      ProxyPassReverse / http://localhost:8083/
</VirtualHost> 

That works like a charm, but now I also want to use apache to serve a site, I would like to do this by making something like /mysite point to /var/www, but I can't really figure out how to do this or if it is even possible.

Any ideas?

like image 665
ErikL Avatar asked Jan 29 '14 19:01

ErikL


1 Answers

I think you have two options:

1. Put the proxy in a separate <Location /someurl> and put the site outside. Requests to http://localhost/someurl/ will be proxied, everything else is the local site:

<VirtualHost *:80> 
    <Location /someurl >
        # Password protection omitted for brevity
        ProxyPass http://localhost:8083/
        ProxyPassReverse http://localhost:8083/
    </Location>

    # Here is the site
    DocumentRoot /var/www
    # ... etc site config
</VirtualHost> 

2. Use two separate VirtualHosts, one for the proxy and one for the site. You will need two separate hostnames pointing to your local ip. For local operations only, use /etc/hosts. In this exemple http://a.localhost/ is the proxy, http://b.localhost is the site:

/etc/hosts:

127.0.0.1       a.localhost
127.0.0.1       b.localhost

Apache config:

# This is the proxy, http://a.localhost/
<VirtualHost *:80> 
    ServerName a.localhost
    # Do password protection as needed
    ProxyPass / http://localhost:8083/
    ProxyPassReverse / http://localhost:8083/
</VirtualHost>

# This is the site, http://b.localhost/
<VirtualHost *:80> 
    ServerName b.localhost
    DocumentRoot /var/www
    # ... etc site config
</VirtualHost>

I would probably go for two separate VirtualHosts, keeping stuff nicely separated.

like image 143
grebneke Avatar answered Sep 18 '22 21:09

grebneke