By Freelance
WordPress Montréal Développeur
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.
But I have like 8 sec for any page in prestashop to load this page (8sec only for the Time To First Byte)
nginx.conf :
user www-data;
worker_processes auto;
worker_priority 15;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 20;
client_max_body_size 15m;
client_body_timeout 60;
client_header_timeout 60;
client_body_buffer_size 10K;
client_header_buffer_size 1k;
large_client_header_buffers 4 8k;
send_timeout 60;
reset_timedout_connection on;
types_hash_max_size 2048;
server_tokens off;
gzip on;
gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 2;
gzip_min_length 512;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/css text/javascript text/xml text/plain text/x-component
application/javascript application/x-javascript application/json
application/xml application/rss+xml font/truetype application/x-font-ttf
font/opentype application/vnd.ms-fontobject image/svg+xml;
# Disable for IE < 6 because there are some known problems
#fastcache
fastcgi_cache_path /etc/nginx-cache levels=1:2 keys_zone=phpcache:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
include /etc/nginx/blacklist.conf;
include /etc/nginx/sites-enabled/*;
}
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 a lot :)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
To improve the TTFB and overall website performance, consider the following steps:
Optimize Database Queries:
PHP-FPM Configuration:
/etc/php/{version}/fpm/pool.d/ directory) to ensure it’s tuned for your server’s resources.pm (process manager) settings, such as pm.max_children, pm.start_servers, and pm.min_spare_servers, to match your server’s capacity.Server Resources:
Nginx Configuration:
expires directive to set cache expiration headers for static assets.Content Compression:
Minimize HTTP Requests:
Content Delivery Network (CDN):
Optimize Images:
Browser Caching:
Reduce Third-Party Requests:
- Minimize the use of external scripts and resources from third-party domains as they can slow down your website.
- Implement preloading for essential assets using the `rel="preload"` attribute in HTML. This can improve the perceived loading speed of your website.
- Use Content Delivery Optimization (CDO) techniques like HTTP/2 and HTTP/3 to enhance the speed of loading resources.
- Implement full-page caching or object caching if applicable and appropriate for your website. Tools like Varnish or Redis can be used for this purpose.
- Use tools like New Relic, Blackfire, or your server's performance monitoring utilities to diagnose bottlenecks and identify performance issues.
- Ensure your SSL/TLS configuration is optimized. Use modern TLS protocols and ciphers to minimize the SSL handshake time.
- Consider using a Let's Encrypt certificate, which is free and easy to configure.
- Review and optimize your PrestaShop theme and extensions. Remove any unnecessary or resource-intensive modules.
- Keep your server's operating system, Nginx, MySQL, PHP, and PrestaShop up to date with the latest security patches and updates.
By following these optimization steps and regularly monitoring your website’s performance, you should be able to significantly reduce the Time To First Byte (TTFB) and improve the overall loading speed of your PrestaShop website on a LEMP stack with SSL/TLS enabled.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.