Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Mon Jan 13, 2014 7:51 am 
Offline
Senior Newbie

Joined: Sat Nov 16, 2013 11:46 am
Posts: 17
Hi,

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!


Top
   
PostPosted: Mon Jan 13, 2014 6:15 pm 
Offline
Junior Member

Joined: Fri Nov 01, 2013 8:16 am
Posts: 21
Website: http://purbeckpixels.com
Location: England
I wrote a little about my Apache/nginx reverse-proxy setup here:

https://forum.linode.com/viewtopic.php?f=12&t=10568#p61207

Here's an example Apache virtual host file:

Code:
<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:

Code:
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; }
}


Top
   
PostPosted: Tue Jan 14, 2014 2:39 am 
Offline
Senior Newbie

Joined: Sat Nov 16, 2013 11:46 am
Posts: 17
Thanks Nicholas.

How do you handle parked domains?
On apache i've added them all as serverAlias and use .htaccess to redirect to the 'main' domain.


Top
   
PostPosted: Tue Jan 14, 2014 6:06 am 
Offline
Junior Member

Joined: Fri Nov 01, 2013 8:16 am
Posts: 21
Website: http://purbeckpixels.com
Location: England
Parked domain Apache virtual host file:

Code:
<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:

Code:
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; }
}


Top
   
PostPosted: Sat Jan 18, 2014 10:03 am 
Offline
Senior Newbie

Joined: Sat Nov 16, 2013 11:46 am
Posts: 17
Hi Nicholas,

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:


Code:
server {
listen 80;
server_name site1;
root /var/www/site1;
location / { proxy_pass http://127.0.1.1:8080; }
 }


Code:
server {
listen 80;
server_name site2;
root /var/www/site2;
location / { proxy_pass http://127.0.1.1:8080; }
 }


and these from apache:

Code:
<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>


Code:
<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

Code:
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?


Top
   
PostPosted: Sat Jan 18, 2014 10:27 am 
Offline
Senior Newbie

Joined: Sat Nov 16, 2013 11:46 am
Posts: 17
Update: Changed to proxy_pass http://127.0.0.1:8080; and it seems fine now.
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 :-)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group