Skip to content

Instantly share code, notes, and snippets.

@choyno
Created November 2, 2018 01:38
Show Gist options
  • Save choyno/dd4c6ec39a78b3296c3ae5893ce65eb4 to your computer and use it in GitHub Desktop.
Save choyno/dd4c6ec39a78b3296c3ae5893ce65eb4 to your computer and use it in GitHub Desktop.
Enable VirtualHosts and Proxy in Apache config
Edit /private/etc/apache2/httpd.conf in your text editor. Uncomment the following lines (remove the "#")
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
Include /private/etc/apache2/extra/httpd-vhosts.conf
Create VirtualHosts for your site
Edit /private/etc/apache2/extra/httpd-vhosts.conf in your text editor. Add the following to the end of the file:
<VirtualHost *:80>
ServerName site1.localhost
ProxyPreserveHost on
ProxyPass / http://localhost:3000/
</VirtualHost>
<VirtualHost *:80>
ServerName site2.localhost
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
</VirtualHost>
You can change localhost to any URL you want. Just don't use .dev because Chrome will force redirect it to HTTPS.
To test if there are no errors in modifying the Apache config, run apachectl -S.
Add your URLs to hosts file
Edit /etc/hosts file.
Add the following lines (use your URLs accordingly)
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost
Restart Apache and flush DNS cache
$ sudo apachectl restart
$ dscacheutil -flushcache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment