1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Plesk 11 + Apache + Nginx + Varnish cache

Discussion in 'Plesk 11.x for Linux' started by Protazy, Sep 12, 2012.

  1. Protazy

    Protazy New Pleskian

    10
    35%
    Joined:
    Sep 12, 2012
    Messages:
    5
    Likes Received:
    0
    Plesk 11 + Apache + Nginx + Varnish cache (Solved)

    Hi there, I have a small problem with setting up a configuration like Plesk + Apache + NginX + Varnish. I used to run similar configuration but without apache. Now since Plesk 11 started to support nginx I decided to run it the way Plesk provides. I have everything working just fine but Varnish. Is there any way to move nginx to port lets say 8080 so Varnish can serve on 80? for example command similar to this one websrvmng --set-http-port --port=8080 ? I'm looking for a solution where I wouldn't have to edit any config files after adding a new domain.
    If someone knows, please share :)
    Kind regards
    Paaul
     
    Last edited: Oct 2, 2012
  2. Alexey.Plotnitsky

    Alexey.Plotnitsky Regular Pleskian

    16
    55%
    Joined:
    Jan 19, 2012
    Messages:
    218
    Likes Received:
    3
    Hi Paaul,

    You can define a desired listen port for Nginx in Plesk default templates for Nginx server:
    /usr/local/psa/admin/conf/templates/default/nginx.php
    /usr/local/psa/admin/conf/templates/default/nginxDomainForwarding.php
    /usr/local/psa/admin/conf/templates/default/nginxDomainVhost.php

    However, please do not modify these files above. You should copy them into the folder below and there you can adjust the listen port.
    /usr/local/psa/admin/conf/templates/custom/

    Here is example how the listen port can be changed for Apache:
    http://download1.parallels.com/Ples...figuration-guide/index.htm?fileName=64631.htm

    P.S.
    Why do you need Nginx if you have Varnish?
    Are you serving static content with Nginx?
     
  3. Protazy

    Protazy New Pleskian

    10
    35%
    Joined:
    Sep 12, 2012
    Messages:
    5
    Likes Received:
    0
    Hello Alexey.Plotnitsky, thanks for your replay, will try it asap.
    Well I'm hosting a magento store which has a lot of photos. Many, but many people recommend to use nginx for use with magento. I tried it and I have to admit that I noticed a really nice speed leap. Magento support Varnish via extension. If it exists and can speed things up a bit more during rush hours, I don't see any reason why not to put it in front of nginx ;)

    Kind regards
    Paul
     
  4. JerzyB

    JerzyB New Pleskian

    10
     
    Joined:
    Jun 1, 2012
    Messages:
    2
    Likes Received:
    0
    could you write a small HowTo with Plesk 11 and Apache? Are you running IIS? I want to run Pleask Without IIS on windows Server 2008... Is there any chance to do it?

    Regards.
     
  5. Protazy

    Protazy New Pleskian

    10
    35%
    Joined:
    Sep 12, 2012
    Messages:
    5
    Likes Received:
    0
    No I don't run IIS. It is hard to say for me if it is possible, because I have never worked with Windows servers. I've solved my problem like this: Apache listens on port 7080 by default when Nginx is activated in Plesk. Nginx listens on 80, I used varnish also with default settings (por 6081), but pointed backend to Apache on port 7080. In Nginx configuration file (in templates as well) I changed pass_proxy from 7080 to 6081. And that's it. In this way nginx checks first if content is cached in varnish, if not then goes to apache. In my setup running magento I noticed about 1 sec speed gain when varnish has files already cached. This is what I wanted :) Pages loading in approx. 0.25 sec :)
     
    Last edited: Oct 2, 2012
  6. JerzyB

    JerzyB New Pleskian

    10
     
    Joined:
    Jun 1, 2012
    Messages:
    2
    Likes Received:
    0
    You are the master then :)

    Thank you for your reply. I sort out my problem as well... I just get Ubuntu with Plesk for www and I run my game on separate machine :)

    Regards.
     
  7. MarkusMarcel

    MarkusMarcel New Pleskian

    10
     
    Joined:
    Oct 9, 2012
    Messages:
    1
    Likes Received:
    0
    Hello,

    I make this of the post, but it doesn´t work by me:
    I change only the nginx.php like:

     
    Last edited: Oct 9, 2012
  8. Protazy

    Protazy New Pleskian

    10
    35%
    Joined:
    Sep 12, 2012
    Messages:
    5
    Likes Received:
    0
    I looked at your config file once again and it seems to be OK. The only thing I can spot is:
    You have backend admin here twice. One of them should be default
    backend default {
    .host = "127.0.0.1";
    .port = "7080";
    }
    or if you want to name it in a different way like frontend, then try this:
    backend frontend {
    .host = "127.0.0.1";
    .port = "7080";
    }

    and in default.vcl put this code changing your domain right after sub vcl_recv { so it looks like this:

    sub vcl_recv {
    if (req.http.host ~ "(?i)^(www.)?yourdomain.com$") {
    set req.backend = frontend;
    }
     
    Last edited: Oct 12, 2012
  9. FanisT

    FanisT New Pleskian

    10
    35%
    Joined:
    Nov 5, 2012
    Messages:
    5
    Likes Received:
    0
    nginx -> varnish -> apache for drupal

    @Protazy thanks for the idea ! I managed to get this working for my drupal installation.

    @MarkusMarcel i think you have to change all three files (not only nginx.php) :

    This is my procedure:

    ( first copy templates files in a new folder named "custom" inside /usr/local/psa/admin/conf/templates/ per #2 comment)

    /usr/local/psa/admin/conf/templates/custom/nginx.php
    /usr/local/psa/admin/conf/templates/custom/nginxDomainForwarding.php
    /usr/local/psa/admin/conf/templates/custom/nginxDomainVhost.php

    then i made these modifications, actually i modified the port varnish listens (in my case this is 6081 for varnish)

    for nginx.php
    for nginxDomainForwarding.php
    for nginxDomainVhost.php
    Then i stopped nginx service from INSIDE my plesk panel then again start nginx service (no just restarting). This is to ensure that scripts will run and make the modifications for all virtual servers on my machine.

    That's it.

    My concerns now is than what is going to happen if varnish crashes. Though this is not a plesk panel issue to discuss here, is there any way for nginx to fall back to apache in the event of a varnish crash ?

    Thanks !

    EDIT: Just to clarify that this configuration is not as this post's title : Varnish -> nginx -> Apache "Sandwich" but rather is nginx -> Varnish -> apache
     
    Last edited: Nov 5, 2012
  10. Alexey.Plotnitsky

    Alexey.Plotnitsky Regular Pleskian

    16
    55%
    Joined:
    Jan 19, 2012
    Messages:
    218
    Likes Received:
    3
    Hi FanisT,

    In order to instruct Nginx to swithch backend servers in case of failure you can use a Nginx config directive upstream:
    http://nginx.org/en/docs/http/ngx_http_upstream_module.html

    You should define new section in nginx config: "upstream backend". There you should specify your backend servers (varnish and apache) with appropriate values for weight, max_fails and fail_timeout.
     
  11. FanisT

    FanisT New Pleskian

    10
    35%
    Joined:
    Nov 5, 2012
    Messages:
    5
    Likes Received:
    0
    No gain with nginx in front of Varnish

    Alexey.Plotnitsky thanks for this information ! I knew that nginx rocks.
    I will try this, but now, here comes your question again:
    This is true in my configuration. I have mostly drupal installations in my server. Varnish caches also static files.
    My tests show that if i request my pages directly to Varnish (http://mysite:6081/) then i see no gain at all. Its just the same (with direct requests to Varnish i have a gain of 10 to 20 req. per sec. more than with nginx, when i am in the range of 2000 req. per sec.)

    So why should i have this "sanwich" with no gain and put Varnish on port 80 with no nginx at all ?

    Any ideas ?

    I think i have to find another solution keeping nginx for flexibility.
     
  12. ottomotto

    ottomotto New Pleskian

    10
     
    Joined:
    Feb 4, 2013
    Messages:
    4
    Likes Received:
    0
  13. sinista

    sinista New Pleskian

    3
     
    Joined:
    Oct 17, 2014
    Messages:
    1
    Likes Received:
    0
    Hi,

    we use php5.5 with Plesk 12 and in this case the nginx.php is a little different then posted here. Is there any chance to get updatet info with php5.5? Original file below

    PHP:
    <?php echo AUTOGENERATED_CONFIGS?>

    <?php /** @var Template_VariableAccessor $VAR */ ?>
    <?php 
    /** @var Template_Variable_IpAddress $ipAddress */ ?>

    include "<?php echo $VAR->server->nginx->httpConfDir ?>/plesk.conf.d/ip_default$

    <?php echo $VAR->includeTemplate('server/nginxVhosts.php', array(
        
    'ssl' => false,
        
    'frontendPort' => $VAR->server->nginx->httpPort,
        
    'backendPort' =>  $VAR->server->nginx->httpPort,
    )) 
    ?>

    <?php echo $VAR->includeTemplate('server/nginxVhosts.php', array(
        
    'ssl' => true,
        
    'frontendPort' => $VAR->server->nginx->httpsPort,
        
    'backendPort' => $VAR->server->webserver->httpsPort,
    )) 
    ?>


    <?php /* Next block used for watchdog */ ?>

    <?php if (!$VAR->server->ipAddresses->hasIpV4Address): ?>
    server {
        listen 127.0.0.1 default_server;
        return 200;
    }
    <?php endif ?>
    best regards http://www.noteboox.de/
     
    Last edited: Dec 9, 2014
Loading...