[Linux] Virtual host with mod_proxy on Apache2
S1. Enable mod proxy
- http to http
• Enable virtual host:
+ AllowEncodedSlashes On - if don't allow, you can not access to Proxypass througt proxy if have encoded slash (%2F) (on NGINX, it allow by default)
For example: http://couchdb.chungkol.com have proxypass http://10.10.121.22:5984, and you have URL: http://couchdb.chungkol.com/check-encoded-slashes%2Fcheckdone, you can not convert to http://couchdb.chungkol.com/check-encoded-slashes/checkdone. This popular proplem in couchdb with proxy apache.
sudo a2enmod proxyAdd a file virtual host /etc/apache2/sites-available/example.file
sudo a2enmod proxy_http
sudo service apache2 restart
- http to http
<VirtualHost *:80>- https to https
ServerAdmin your@email.com
ServerName example.com
ServerAlias www.example.com
ProxyRequests off
AllowEncodedSlashes On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
DocumentRoot /var/www
ErrorLog ~/apache2/logs/error.log
CustomLog ~/apache2/logs/access.log combined
</VirtualHost>
<VirtualHost 192.168.2.239:443>
ServerName mail.example.com
DocumentRoot /var/www
ProxyRequests off
AllowEncodedSlashes On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
SSLEngine on
SSLProxyEngine On
SSLCertificateFile /etc/ssl/certs/mhongchung_tk.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / https://192.168.2.235/
ProxyPassReverse / https://192.168.2.235/
</VirtualHost>
• Enable virtual host:
a2ensite example.com• Disable virtual host
a2dissite example.com
Notes:
+ ProxyRequests off - your proxy not a open proxy that no one can use it for access to internet+ AllowEncodedSlashes On - if don't allow, you can not access to Proxypass througt proxy if have encoded slash (%2F) (on NGINX, it allow by default)
For example: http://couchdb.chungkol.com have proxypass http://10.10.121.22:5984, and you have URL: http://couchdb.chungkol.com/check-encoded-slashes%2Fcheckdone, you can not convert to http://couchdb.chungkol.com/check-encoded-slashes/checkdone. This popular proplem in couchdb with proxy apache.