Skip to content

Instantly share code, notes, and snippets.

@boobo94
Last active June 25, 2018 19:42
Show Gist options
  • Save boobo94/90a4b5bd2b16261b8b5e8dfc91dad147 to your computer and use it in GitHub Desktop.
Save boobo94/90a4b5bd2b16261b8b5e8dfc91dad147 to your computer and use it in GitHub Desktop.
Configure a server as proxy with apache2
  1. create file /etc/apache2/sites-available/VIRTUALHOST_NAME.conf
  2. sudo a2ensite virtual_host_file_name
  • to disable an existing conf file sudo a2dissite virtual_host_file_name
  1. copy file in /etc/apache2/sites-enabled/VIRTUALHOST_NAME.conf
  2. install ssl module sudo a2enmod ssl
  3. install proxy module sudo a2enmod proxy
  4. install rewrite module sudo a2enmod rewrite
  5. install proxy_connect module sudo a2enmod proxy_connect
  6. install proxy_http module sudo a2enmod proxy_http
  7. sudo service apache2 reload

Other commands for apache:

  • show all modules installed apache2ctl -M
  • show logs sudo systemctl status apache2.service

References

  • DESIRED_PORT: represent the port where your current local server is running (node/go/etc server)
  • URL_ADDRESS: your DNS
<VirtualHost *:80>
# without http or https
ServerName URL_ADDRESS
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.DOMAIN\.com$
RewriteRule ^/(.*)$ https://%1.DOMAIN.com/$1 [R=301,L]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin EMAIL
# without http or https
ServerName URL_ADDRESS
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
SSLEngine on
SSLCertificateFile /home/ubuntu/certificates/certificate.crt
SSLCertificateKeyFile /home/ubuntu/certificates/certificate.key
SSLCertificateChainFile /home/ubuntu/certificates/certificate.ca.crt
</VirtualHost>
</IfModule>
<VirtualHost *:80>
# without http or https
ServerName URL_ADDRESS
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.DOMAIN\.com$
RewriteRule ^/(.*)$ https://%1.DOMAIN.com/$1 [R=301,L]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin EMAIL
# without http or https
ServerName URL_ADDRESS
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
SSLEngine on
SSLCertificateFile /home/ubuntu/certificates/certificate.crt
SSLCertificateKeyFile /home/ubuntu/certificates/certificate.key
SSLCertificateChainFile /home/ubuntu/certificates/certificate.ca.crt
</VirtualHost>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment