How to access to symfony Dev environnement behind varnish? - symfony

After installing varnish in front of apache2, I can not access the dev environment of symfony2 project (connected from localhost, so it worked before installing varnish).
I got the symfony2 access denied message "You are not allowed to access this file. Check app_dev.php for more information."
When looking into app_dev.php file:
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
After debuging the problem, i found that the $_SERVER['HTTP_CLIENT_IP'] is NULL.
How to fix this ?
Thank you.
Note: I'm using ubuntu 14.04 + apache2.4 + varnish 3 + Symfony2.4

The line would return a 403 if either:
HTTP_CLIENT_IP header is present
HTTP_X_FORWARDED_FOR header is present
$_SERVER['REMOTE_ADDR'] is not one of '127.0.0.1', 'fe80::1', '::1'
Probably you are setting the HTTP_X_FORWARDED_FOR header in varnish, or varnish is setting it for you, depending on the varnish version. Unset it or rewrite the condition, it's a safety measure so act accordingly.
You have some interesting info here: http://symfony.com/doc/current/cookbook/cache/varnish.html

Related

Wordpress Varnish vcl Configuration

When I user apache in Varnish vcl config set :
.expected_response = 200;
and everything works correctly but when to install Litespeed I should change this parameter to :
.expected_response = 301;
What's the reason for this issue? Is this configuration right, or causing the other problem?
Basically people using LiteSpeed Web Server may want to use LSCache instead of Varnish. There're many reasons but I am not going to explain here.
You said with Litespeed only expect 301 status. It's possible something in the rewrite rules causing it. Please share the status code with following command.
curl -s -o /dev/null -w "%{http_code}" https://example.com
If it shows 301, then you may want to check your rewrite rules what making it different between Apache and LiteSpeed.
Best

Varnish + Nginx proxy configuration on plesk

I followed the official tuto for the Varnish via Docker configuration on plesk. https://www.plesk.com/blog/product-t...cker-container
i have a VPS Ubuntu with plesk and many domains.
I followed all steps :
I created a domain test.monserveur.com
I use the Docker image million12/varnish
On the Docker container setting, the mapping redirect the 80 port to the 32780
On plesk for the hosting parameters, the option “SSL/TLS support” and “Permanent SEO-safe 301 redirect from HTTP to HTTPS” are deactivated
I deactived also the security mod for this domain
On the proxy rules of the docker container (/etc/varnish/default.vcl), i put fo the .host test.monserveur.com and .port 7080
On the function sub vcl_deliver, i put :
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
I still have a 503 page with a MISS on the header for the page on test.monserveur.com
I can't understand where is the problem. I tried to put on the .host the serveur IP and with a link to another domain of the server. I think it's a problem with a setting but i don't know where.
Thanks in advance
A 503 error response from Varnish means that your Docker container is not configured properly. You should check whether the container and Varnish within the container are running properly. Additionally, the configuration file must have valid syntax and the correct port and IP address of the server have to be set in the configuration file.
Without knowing what you've entered, I cannot give you a better advice! If you follow the tutorial completely, it will work. I've created over 10 working instances while I wrote the text!
PS: Please use the official Plesk forum with more information (also add your configuration file) if you still cannot solve your problem - https://talk.plesk.com/
Have success!

How test if varnish is working (HIT or MISS)

I added in varnish file "default.vcl" a code for check if Varnish cache is working but I get a Transfer-Encoding "Chunked" and I cant see if Cache is working displaying HIT or MISS. I follow next tutorial and I believe have some port in nginx blocking his right function.
Code added within of "sub vcl_deliver":
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
My settings:
Apache 2.4.6 port by default 7080
etc/nginx/nginx.conf without port by default (without port added)
etc/nginx/plesk.conf.d/server.conf > server listen port MyIP:80 (default)
Varnish port 80 to external 32780 (Added from plesk)
etc/varnish/default.vcl: In host my IP and in port 7080
How can delete "Transfer-Encoding Chunked" and remplace it for "X-Cache MISS or HIT" to show in headers ?
Best regards

How to setup Wordpress with https://box.scotch.io/?

I have setup scotch box and now trying to setup WordPress with scotch box how would I go by doing this please.
I have recently set this up.
To set up Wordpress, place the Wordpress install files inside the scotch/public folder that is created when you first run scotch.io
You will then need to ssh into your vagrant box, and set up a new MySQL database. You can import a dump via the command line, or export/import using Sequel like I did.
Even though mod_rewrite is already enabled in scotch.io, I found it helpful to restart the apache2 server in the vagrant box.
Once that's done - you should be able to navigate to 192.168.33.10 on your browser to see your install.
Set the wp_config.php database host to localhost.
I found the following code great for getting permalinks working, place this at the top of your wp_config file:
$s = empty($_SERVER['HTTPS']) ? '' : ($_SERVER['HTTPS'] == 'on') ?
's' : '';
$port = ($_SERVER['SERVER_PORT'] == '80') ? '' : (":".$_SERVER['SERVER_PORT']);
$url = "http$s://" . $_SERVER['HTTP_HOST'] . $port;
define('WP_HOME', $url);
define('WP_SITEURL', $url);
unset($s, $port, $url);
If you get a Database access error - this is a good sign you're on the right track, you need to put in the user: root / pass: root details fro the vagrant web host to access the database inside the box.

getting error while using lua with nginx

I am very new to nginx and lua .i have installed Openresty .
below is my code in nginx.conf file .
server{
location /hellolua {
default_type 'text/plain';
content_by_lua ' local name = ngx.var.arg_name or "Anonymous"
ngx.say("Hello, ", name, "!") ';
}
}
When i am running sudo service nginx start i am getting error Starting nginx: nginx: [emerg] unknown directive "content_by_lua" in /etc/nginx/nginx.conf:24
nginx: configuration file /etc/nginx/nginx.conf test failedt
Please let me know what i am missing .
It seems to me, as if you haven't installed the right module? ngx_lua (http://wiki.nginx.org/HttpLuaModule)
You mention OpenResty. Did you configure it with lua? If not, the guide is here(http://wiki.nginx.org/HttpLuaModule#Installation).
Quick resumé:
The ngx_openresty bundle can be used to install Nginx, ngx_lua, either one of the standard Lua 5.1 interpreter or LuaJIT 2.0, as well as a package of powerful companion Nginx modules. The basic installation step is a simple ./configure --with-luajit && make && make install.
You can manually compile ngx_lua into nginx too, the full guide is in the link too.
After comment-discussing - I removed the irrelevant part of the answer.
By default, OpenResty's nginx is installed into the path /usr/local/openresty/nginx/sbin/nginx. Your system's default nginx init configurations need an update to point to the right locations.

Resources