Skip to content

Instantly share code, notes, and snippets.

@1v
Last active May 31, 2018 16:45
Show Gist options
  • Save 1v/7473b4acbaac0d79877d to your computer and use it in GitHub Desktop.
Save 1v/7473b4acbaac0d79877d to your computer and use it in GitHub Desktop.
Nginx behind Apache

Nginx behind Apache

Install mod_proxy_http:

a2enmod proxy_http

Add to /etc/apache2/apache2.conf (change ip):

<VirtualHost 11.1.11.111:80 >
	ServerName site.com
	ServerAlias *.site.com
	CustomLog /var/www/httpd-logs/site.com.access.log combined
	ErrorLog /var/www/httpd-logs/site.com.error.log
	ProxyPass / http://localhost:8080/
	ProxyPassReverse / http://localhost:8080/
	ServerAdmin webmaster@site.com
	SuexecUserGroup user user
</VirtualHost>

Add to /etc/apache2/mods-available/proxy.conf:

<IfModule mod_proxy.c>

ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

</IfModule>

Restart apache:

sudo service apache2 restart

In nginx site config specify port and upsteam:

upstream ContactAppProduction {
  server              unix:///tmp/MyAppProduction.sock;
}

server {
  listen              *:8080;
  server_name         site.com;

In /etc/nginx/conf.d/default.conf change port from 80 to something else:

server {
    listen       3000;

Restart nginx:

sudo service nginx restart

Than run app just with upstream. See.

See also

@Nessworthy
Copy link

Just a heads up - if you found this through google like me and got stuck on proxypassing when SSL is involved, you'll want to look at the SSLProxyEngine, SSLProxyCheckPeerCN, SSLProxyCheckPeerExpire directives for apache!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment