Nginx + Varnish + ISPConfg = it's posible?

Discussion in 'Installation/Configuration' started by daviz_zamora, May 12, 2014.

  1. daviz_zamora

    daviz_zamora New Member

    I was able to solve most of the problems with this control panel, I only need to run Nginx and Varnish with ISPConfig, it would be possible?

    I have ISPConfig on port 8080 (by default) and nginx in 80, if I tell Varnish to listen on 8080, entered: dominio.com and I do not load my page, I jump nginx error: 'Welcome to nginx '

    What is it?

    Thanks
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    This should work without problems, I just configured it with apache instead of nginx for a customer.

    all you have to do is to customize the vhost template so that nginx uses e.g. port 8082 instead of port 80. then configure varnish to listen on port 80. The ispconfig vhost on port 8080 does not ahs to be altered at all, as I guess you want to sped up websites and not the ispconfig ui.
     
  3. daviz_zamora

    daviz_zamora New Member

    Yes, but not working :(
     
  4. Kubek

    Kubek New Member

    You have to configure VARNISH to listen on port 80 and nginx to be behind on port 8090 for example. Then rewrite your default config templates in directory "/usr/local/ispconfig/server/conf/"
     
  5. vm2014

    vm2014 New Member

    Could someone please comment on the rewrite in more detail? I went through and setup varnish in front of Apache.

    Out of the box I was able to test all of my sites on example.com:6801 the varnish default port. I moved varnish up to port 80 by editing /etc/defaults/varnish and /etc/varnish/default.vcl. But changing the ISPConfig default from port 80 on the other hand does not appear to be a straightforward endeavor. Editing /usr/local/ispconfig/server/conf/apache_ispconfig.conf.master (or nginx_vhost.conf.master if your are on nginx) shows several port 80 references and some code:

    Code:
    NameVirtualHost {tmpl_var name="ip_address"}:{tmpl_var name="port"}
    Where is tmpl_var_name defined? So that it can be changed properly. Are the port setting in ISPConfig (System/Server IP addresses) the source? Then why are there any ports hard-coded in the conf file?

    Also, do the master files get replaced on ISPConfig updates? Is there a better place to make these changes?

    After seeing the dramatic speed increase and reduced CPU load vs apache, I can foresee varnish / nginx reverse proxy always on my servers and would love for this to be the new standard for ISPConfig installs.
     
    Last edited: May 28, 2014
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    There are no changes in the ispconfig sources required. All you have to do is to modify the vhost.conf.master template file and store it on conf-custom folder. Replace the line:

    <VirtualHost {tmpl_var name='ip_address'}:{tmpl_var name='port'}>

    with e.g.:

    <tmpl_if name='port' op='==' value='80'>
    <VirtualHost localhost:8082>
    <tmpl_else>
    <VirtualHost {tmpl_var name='ip_address'}:{tmpl_var name='port'}>
    </tmpl_if>
     
  7. vm2014

    vm2014 New Member

    Is there a way to force the rebuild of the .vhosts files after doing this? I have made several changes and can't seem to get the vhosts to rebuild after the first change.
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    See Tools > Resync
     
  9. Kubek

    Kubek New Member

    1. Go to ISPConfig panel
    2. Go to Tools
    3. Click Resync in the sidebar
    4. Check Websites and click start

    I hope thats what you want.

    Edit: uh ... Till was first
     
  10. vm2014

    vm2014 New Member

    I did try the resync, but it appears to try to modify the .vhosts files not replace them. Some of my deletions are not deleting and caused lots of chaos. I restored a backup of the /sites-avilable and all is working after I gave up on the resync and site edit save attempts.

    Sorry to all for hijacking this thread over to apache, I still want to clarify the instructions for using varnish in front of either apache or nginx.

    Note to all: make a quick backup of your conf and vhost files before attempting to enable varnish.
     
    Last edited: May 28, 2014
  11. daviz_zamora

    daviz_zamora New Member

    nginx archive's is:

    - nginx_apps.vhost.master

    server {
    listen {apps_vhost_ip}{apps_vhost_port};

    server_name {apps_vhost_servername};

    root {apps_vhost_dir};

    client_max_body_size 20M;

    location / {
    index index.php index.html;
    }

    # serve static files directly
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
    access_log off;
    }

    location ~ \.php$ {
    try_files $uri =404;
    ...

    - nginx_vhost.conf.master:
    server {
    listen <tmpl_var name='ip_address'>:80;
    <tmpl_if name='ipv6_enabled'>
    listen [<tmpl_var name='ipv6_address'>]:80;
    </tmpl_if>

    <tmpl_if name='ssl_enabled'>
    listen <tmpl_var name='ip_address'>:443 ssl;
    <tmpl_if name='ipv6_enabled'>
    listen [<tmpl_var name='ipv6_address'>]:443 ssl;
    </tmpl_if>
    ssl_certificate <tmpl_var name='document_root'>/ssl/<tmpl_var name='ssl_domain'>.crt;
    ssl_certificate_key <tmpl_var name='document_root'>/ssl/<tmpl_var name='ssl_domain'>.key;
    </tmpl_if>

    server_name <tmpl_var name='domain'> <tmpl_var name='alias'>;

    root <tmpl_var name='web_document_root_www'>;

    ...

    which I have to change? already listening on port 80, right?

    Thank you very much!!!!

    If I change the port to 8080 nginx does not work my web :(
     
    Last edited: May 28, 2014
  12. vm2014

    vm2014 New Member

    Varnish will be the server on port 80. Apache or Nginx needs to be moved to an alternate port like 8082. Requests will come in from the public on 80 and hit varnish. Varnish will either serve from the cache or make a request for example.com:8082 to fetch the php/html/jpg/etc. from apache or nginx and then pass that along to the client on 80.
     
  13. vm2014

    vm2014 New Member

    You don't want to use 8080 as ISPConfig is listening on 8080.
     
  14. Kubek

    Kubek New Member

    You need to change it to

    Code:
    server {
            listen <tmpl_var name='ip_address'>:8090;
    <tmpl_if name='ipv6_enabled'>
            listen [<tmpl_var name='ipv6_address'>]:8090;
    </tmpl_if>
    		
    <tmpl_if name='ssl_enabled'>
            listen <tmpl_var name='ip_address'>:443 ssl;
    <tmpl_if name='ipv6_enabled'>
            listen [<tmpl_var name='ipv6_address'>]:443 ssl;
    </tmpl_if>
            ssl_certificate <tmpl_var name='document_root'>/ssl/<tmpl_var name='ssl_domain'>.crt;
            ssl_certificate_key <tmpl_var name='document_root'>/ssl/<tmpl_var name='ssl_domain'>.key;
    </tmpl_if>
            
            server_name <tmpl_var name='domain'> <tmpl_var name='alias'>;
    
            root   <tmpl_var name='web_document_root_www'>;
    
    Then open varnish config (if you are on debian/ubuntu it is "/etc/default/varnish")

    And make sure you have these lines in that file:

    Code:
    DAEMON_OPTS="-a :80 \
                           -T localhost:6082 \ 
    
    Next also make sure you have these line in default varnish ".vlc" config (it should be at "/etc/varnish/default.vcl")

    Code:
    backend default {
      .host = "127.0.0.1";
      .port = "8090";
    }
    
    so the Varnish can listen on port 80. Which is entry point from if you are not using SSL. I am not sure how to setup Varnish if you want to use it with SSL enabled site as I have not tried it on such site yet. In example I wrote above if someone will access your site via HTTPS, they will be still served with Nginx (not a problem at all).

    Don't forget to reload Nginx and restart Varnish.

    Hope it helps.
     
    Last edited: May 29, 2014
  15. daviz_zamora

    daviz_zamora New Member

    Changed, but say error nginx... :(
     
  16. daviz_zamora

    daviz_zamora New Member

    Up, any idea? :(
     
  17. Kubek

    Kubek New Member

    Please show me your nginx error log located at /var/log/nginx/error.log
     
  18. daviz_zamora

    daviz_zamora New Member

    Yes, look:
    /var/log/nginx/error.log

    2014/08/18 14:48:27 [error] 10378#0: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: XX.XX.XX.XX, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "domain.com"
    2014/08/18 14:48:27 [error] 10378#0: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: XX.XX.XX.XX, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "dmonain.com"

    Thanks.

    Can not access in my website, i type in browser 'domain.com', but say error nginx:

    [​IMG]

    If i change port nginx by '80', charged my website and all ok...
     
    Last edited: Aug 18, 2014
  19. Kubek

    Kubek New Member

    Well I will make wild guess here ... You have probably installed nginx twice - from repository + your own compiled version. The problem is that "/usr/share/nginx/html/" doesnt look like root directory set in nginx config created by ISPConfig... It should look like this: "/var/www/domain.com/web".

    The problem is either that you are running the compiled nginx and not the nginx you are want to (so make sure you have only one nginx installed) or that ISPConfig is not configured properly or you are not creating new websites properly (so make sure the ISPConfig installation was successful and you can create site without problems and then try to set up Varnish).
     

Share This Page