Jump to content

Nginx/PHP/SSL on VPS => TTFB > 8secs.


Recommended Posts

Hello community :)

I hosted on VPS with digitalocean, in Singapour (we are located in Australia). I use Prestashop software for my store.
I installed nginx, php-fpm and mysql (LEMP Stack) by myself. No cache activated yet.. (opcache, memechached...)

But I have like 8 sec for any page in prestashop to load this page (8sec only for the Time To First Byte)

 

post-918045-0-07862100-1427372998.png

 

My vhost config :
 

server {

server_name sub.domain.com;
# Normal
listen 80;
return 301 https://$server_name$request_uri;
}


# SSL
server {

listen 443 spdy;

# Error / Access log
error_log /var/log/nginx/domain.com_error.log;
access_log /var/log/nginx/domain.com_access.log;

#ssl :
include '/etc/nginx/conf.d/ssl.conf';

# Server settings :
server_name sub.domain.com;
root /home/usersys/sites/domain.com;
index index.html index.htm index.php;
proxy_buffers 16 16k;
proxy_buffer_size 32k;

# Location php :
include '/etc/nginx/conf.d/location-php.conf';

# Cache static :
include '/etc/nginx/conf.d/cache_static.conf';

# Rewrite rule presta :
include /etc/nginx/conf.d/ps_rewrite_rules.conf;
}

ssl.conf file :
 

ssl on;
ssl_certificate /etc/ssl/www.domain.com.crt;
ssl_certificate_key /etc/ssl/www.domain.com.key;


ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:32m;
ssl_buffer_size 4k;
ssl_session_timeout 10m;

client_max_body_size 15m;
client_body_buffer_size 128k;

ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/ssl/trusted.crt;
resolver 8.8.4.4 8.8.8.8 valid=300s;
resolver_timeout 10s;

ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;

add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;

location-php.conf file :
 

location ~ \.php$ {

try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param HTTPS on;
fastcgi_read_timeout 300;
fastcgi_buffers 256 16k;
fastcgi_buffer_size 32k;
fastcgi_cache phpcache; # The name of the cache key-zone to use
fastcgi_cache_valid 200 30m; # What to cache: 'code 200' responses, for half an hour
fastcgi_cache_methods GET HEAD; # What to cache: only GET and HEAD requests (ot POST)
add_header X-Fastcgi-Cache $upstream_cache_status; # Allow us to see if the cache was HIT, MISS, or BYPASSED inside a browser's Inspector panel
fastcgi_cache_bypass $no_cache; # Dont pull from the cache if true
fastcgi_no_cache $no_cache; # Dont save to the cache if true


include fastcgi_params;

}

cache_static.conf :
 

# Expire rules for static content

# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
# access_log logs/static.log; # I don't usually include a static log
}

# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}

# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|woff|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}

ps_rewrite_rules.conf :
 

rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/order$ /index.php?controller=order last;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php last;
}

Thanks :)

Thanks a lot :)

post-918045-0-07862100-1427372998_thumb.png

Edited by Foovince (see edit history)
Link to comment
Share on other sites

Thanks tuk66 for your answer,

 

I already cleaned modules in my prestashop... all modules seem's necessary... but I ll have a look again ;)

 

But Where its strange, its I have only 6 module hooked on displayTop and when I unhooked cartblock, the response time come under < 1,5sec

 

post-918045-0-89162000-1427410338.png

post-918045-0-89162000-1427410338_thumb.png

Edited by Foovince (see edit history)
Link to comment
Share on other sites

Hey bellini13, thanks for your answer :)

 

I worked today, seem's better now after some modification on my webserver...

 

But I got still 4,5/5sec to add product to cart (with ajax mode enable on cart block module)

 

About 8sec, its was correct, 4554ms + 4479ms > 8sec 

 

also, images have TTFB >3sec (Im using pagespeed)

 

post-918045-0-05735500-1427455098.png

post-918045-0-05735500-1427455098_thumb.png

Link to comment
Share on other sites

  • 3 months later...

I'm running a similar setup but having issues where nginx is caching my session cookies and whenever you visit the site you see it as the person who was the first to get cached. Did you run into this problem at all and if not how are you handling cookies to make sure? 

 

My post is here on the subject:

https://www.prestashop.com/forums/topic/455472-nginx-fastcgi-cache-caching-issues-is-a-unique-cache-for-each-auth-customer-possible/

Link to comment
Share on other sites

You got third party modules and your main issue is TTFB (time to first byte).

 

I had this issue before with IIS and it turned out to be Advanced Parameters -> Disable Overrides? -> Set to NO

 

Clear cache or restart nginx and test your website.

 

Good luck and if this solves your problem, I hope you take some time to help 763Online with his nginx issues.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...