0

Im pretty new to this and this could be a dumb question :/

So I've tried to enable caching on nginx but when I'm reloading the server I'm ending with a "502 Bad Getaway"

I do know which line is breaking everything but I'm not sure why and how to fix it.

proxy_pass http://127.0.0.1/;

If I comment this line the site is working but there is no caching obviously.

Can someone explain me what I'm missing pls?

Whole conf file :

#GE CONFIG (DOT NOT REMOVE!)
include forge-conf/dev.mywebsite.com/before/*;

proxy_cache_path /var/cache keys_zone=one:10m levels=1:2 inactive=60m use_temp_path=off;

map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}

server {
    listen 80;
    server_name dev.mywebsite.com;
    root /home/forge/dev.mywebsite.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/dev.mywebsite.com/server/*;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    #access_log /var/log/mywebsite.acces.log;
    error_log  /var/log/nginx/dev.mywebsite.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location  / {
    try_files $uri $uri/ /index.php?$query_string;

    ###
    # Proxy Swag
    ###

    proxy_pass http://127.0.0.1/;
    proxy_cache one;
    proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;



}

# FORGE CONFIG (DOT NOT REMOVE!)

1 Answer 1

1

You are making an infinite proxy cycle with this configuration, when you are proxying requests from the web server service at port 80 to the same port.

You need to use fastcgi_cache directive for caching FastCGI content.

3
  • I tried to follow this article digitalocean.com/community/tutorials/… but my system is still not caching anything is there a specific reason for this or is it just me failing :/ ?
    – Baldráni
    Dec 27, 2016 at 14:03
  • What is the configuration you are using? Edit it into your question. Dec 28, 2016 at 4:27
  • Okay I spent a lot of hour and cross-check a lot of article but finally made it !
    – Baldráni
    Dec 30, 2016 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .