I have a Magento website that is running on apache2 and the frontend is in PWA and running on Nginx and I'm using Cloudflare. Now want to cache the images but it's always showing BYPASS.
Apache configuration:
<VirtualHost 127.0.0.1:8081>
SSLEngine On
SSLCertificateFile /etc/nginx/ssl/cloudflare.crt
SSLCertificateKeyFile /etc/nginx/ssl/cloudflare.key
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName stg.mydomain.com
ServerAlias stg.mydomain.com
Alias /backend "/var/www/backend/public_html"
DocumentRoot "/var/www/backend/public_html"
<Directory "/var/www/backend/public_html">
DirectoryIndex index.php index.html index.htm
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Nginx configuration:
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /etc/nginx/ssl/cloudflare.crt;
ssl_certificate_key /etc/nginx/ssl/cloudflare.key;
server_name stg.mydomain.com;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
proxy_redirect off;
location / {
proxy_pass http://127.0.0.1:9000;
}
location /backend {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://127.0.0.1:8081;
}
}
I have added the following codes to cache the images on browsers
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /etc/nginx/ssl/cloudflare.crt;
ssl_certificate_key /etc/nginx/ssl/cloudflare.key;
server_name stg.mydomain.com;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
proxy_redirect off;
location / {
proxy_pass http://127.0.0.1:9000;
}
location ~* .(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|webp)$ {
expires 1d;
add_header Cache-Control "public";
}
location /backend {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://127.0.0.1:8081;
}
}