Configuration Nginx Apache Reverse proxy
I'm hosting a couple of sites (some wordpress, some drupal, some regular php) on a Linode using Apache. This sometimes leads to high memory usage.
Because of this I'm thinking about using nginx.
For the statis sites, I suppose I can serve them right from nginx, so no configuration on apache will be needed?
For the wordpress and drupal sites, I'd like to use nginx as reverse proxy.
I've been going through a lot of documentation and configuration examples but I found a lot of contradictions and multiple possibilities.
As I'm running already some production sites, I cannot do a lot of trial and error
Is there somebody who has this kind of setup who's willing to share his/her configuration with me?
Thanks!
5 Replies
Here's an example Apache virtual host file:
<virtualhost *:81="">ServerAdmin webmaster@domain.com
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /var/www/domain
<directory var="" www="" domain="">Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all</directory>
ErrorLog ${APACHE_LOG_DIR}/errors/domain-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/domain-access.log combined</virtualhost>
And an example nginx virtual host file:
server {
listen 80;
server_name domain.com www.domain.com;
access_log off;
error_log off;
location / { proxy_pass http://127.0.0.1:81; }
location ~* ^.+\.(htm|html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|bz2|pdf|odt|txt|tar|bmp|rtf|js|swf|avi|mp4|mp3|ogg|flv)(\?.*)?$ {
expires 30d; #adjust to your static content's update frequency
root /var/www/domain;
}
location ~ /\.ht { deny all; }
}
How do you handle parked domains?
On apache i've added them all as serverAlias and use .htaccess to redirect to the 'main' domain.
<virtualhost *:81="">ServerAlias www.parkeddomain.net
ServerAlias parkeddomain.net
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule (.*) http://www.domain.com$1 [R=301,L]</virtualhost>
Parked domain nginx virtual host file:
server {
listen 80;
server_name parkeddomain.net www.parkeddomain.net;
access_log off;
error_log off;
location / { proxy_pass http://127.0.0.1:81; }
location ~* ^.+\.(htm|html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|bz2|pdf|odt|txt|tar|bmp|rtf|js|swf|avi|mp4|mp3|ogg|flv)$ {
expires 30d; #adjust to your static content's update frequency
}
location ~ /\.ht { deny all; }
}
I followed your guidelines but I think I'm still missing something.
Nginx is always displaying the same site. However when I bypass nginx by adding the port on which apache is running the correct site is shown.
I did a test-setup on a Ubuntu server running in Virtualbox.
These are the nginx virtualhost files:
server {
listen 80;
server_name site1;
root /var/www/site1;
location / { proxy_pass http://127.0.1.1:8080; }
}
server {
listen 80;
server_name site2;
root /var/www/site2;
location / { proxy_pass http://127.0.1.1:8080; }
}
and these from apache:
<virtualhost *:8080="">ServerAdmin webmaster@example.com
ServerName site1
DocumentRoot /var/www/site1
<directory var="" www="" site1="">Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all</directory></virtualhost>
<virtualhost *:8080="">ServerAdmin webmaster@example.com
ServerName site2
DocumentRoot /var/www/site1
<directory var="" www="" site2="">Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all</directory></virtualhost>
When removing the
location / { proxy_pass http://127.0.1.1:8080; }
from the nginx vhost files and stopping the apache server it's working fine.
What could be missing?
I guess I was confused because i saw in some apache logfile the ServerName was 127.0.1.1
next: get this working on the Linode