Question

I have installed varnish on nginx. I have some really big problems.

my default.vcl is:

backend default {
.host = "127.0.0.1";
.port = "81";

}

my website virtual server is:

server {
listen   80;

root /var/www/site.com.ro/public_html;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name www.site.com.ro;

access_log /var/www/site.com.ro/logs/log.access;
error_log /var/www/site.com.ro/logs/log.error error;

location / {
    index index.php;
    try_files $uri $uri/ @handler;
}

location @handler {
    rewrite /   /index.php;
}

location /blog {
    alias /var/www/site.com.ro/public_html_blog/;
    index index.php index.html index.htm;
    try_files $uri $uri/ /blog/index.php;
}

location ~  ^/blog(.+\.php)$ { ### This location block was the solution
    alias /var/www/site.com.ro/public_html_blog/$1;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_read_timeout 300;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    allow 127.0.0.1;
    allow ::1;
    deny all;
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
#   proxy_pass http://127.0.0.1:8080;    
#}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/www;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
    if (!-e $request_filename) {
        rewrite / /index.php last;
    }

    try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_read_timeout 300;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#   deny all;
#}

}

server { listen 80;

# Make site accessible from http://localhost/
server_name site.com.ro;
rewrite ^(.*) http://www.site.com.ro$1 permanent;

}

and the varnish file is:

DAEMON_OPTS="-a :80 \
         -T localhost:6082 \
         -f /etc/varnish/default.vcl \
         -S /etc/varnish/secret \
         -s malloc,256m"

when I try to change the listen port for the website to 81 I get a 500 error... can anyone help me? I don't know what I did wrong.

Was it helpful?

Solution

Varnish is configured to listen to port 80, and connect to localhost:81. nginx is configured to listen to port 80. You didn't mention the intended flow, but I'm taking a wild shot and guessing:

client -> varnish:80 -> nginx:81.

Do you spot the problem now?

Hint:

server {
listen   80;

Oh, and make sure you have a real similar setup in a test machine (virtualbox - or something) that you use when you dabble with settings you're not familiar with. That will give you time to understand why something is not working, and will gain you invaluable experience so you don't have to mess up the production site(s).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top