Nginx 403 error on Akeneo 7 CE when uploading media

56 views Asked by At

I have a weird problem with Akeneo CE 7.0.41 and uploading media to server (product images, avatars, pdf's... etc.)

When uploading any media file, I get 403 forbidden error from Nginx. The POST request is sent to /media route, which in Akeneo filesystem means root/public/media.

The reason for this error has probably something to do with the fact that /media does not have any index file like index.php or index.html in it. It only has one folder called cache.

If I manually create index.php file to the media folder, instead of 403 forbidden I get 500 Internal server error (This feels actually quite obvious).

I also tried uploading image to a product using Akeneo REST API which works fine.

Here's my Nginx conf (variables are handled by Laravel Forge and they are really ok on the server):

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/{{ SITE }}/before/*;

server {
    listen {{ PORT }};
    listen {{ PORT_V6 }};
    server_name {{ DOMAINS }};
    server_tokens off;
    root {{ PATH }};

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

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers <hidden>;
    ssl_prefer_server_ciphers off;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/{{ SITE }}/server/*;

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

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

    access_log off;
    error_log  /var/log/nginx/{{ SITE }}-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass {{ PROXY_PASS }};
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/{{ SITE }}/after/*;

PHP version 8.1

Any ideas on this are appreciated.

Thanks!

1

There are 1 answers

0
Shamppi On BEST ANSWER

Found the answer from Symfony docs.

The original Nginx config made by Laravel forge had the following location block:

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

The proper location block config should be as follows:

location / {
    # try to serve file directly, fallback to index.php
    try_files $uri /index.php$is_args$args;
}

Hope this helps someone else!