pavel
pavel

Reputation: 11

I get 413 nginx error when uploading a file

I am getting 413 error when trying to upload file, below is the code of my nginx.conf and docker-compose

nginx.conf:

http {
    client_max_body_size 500M;

    server {
        listen 80;
        server_name 194.58.119.116;

        root /var/www/public;

        location / {
            try_files $uri /index.php;

            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization';
                return 200;
            }
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }
}

docker-compose:

`version: '3.8'

services: nginx: image: nginx:latest volumes: - ./:/var/www - ./.docker/nginx/conf.d/:/etc/nginx/conf.d ports: - "80:80" depends_on: - app container_name: ${CONTAINER_PREFIX}_nginx environment: PHP_MEMORY_LIMIT: 512M PHP_POST_MAX_SIZE: 500M PHP_UPLOAD_MAX_FILESIZE: 500M

app: image: $REGISTRY/dev/app:$CI_COMMIT_SHA environment: - APP_NAME=$APP_NAME - APP_KEY=$APP_KEY - APP_ENV=$APP_ENV - APP_URL=$APP_URL - DB_CONNECTION=$DB_CONNECTION - DB_HOST=$DB_HOST - DB_PORT=$DB_PORT - DB_DATABASE=$DB_DATABASE - DB_USERNAME=$DB_USERNAME - DB_PASSWORD=$DB_PASSWORD - APP_DEBUG=$APP_DEBUG volumes: - ./:/var/www depends_on: - db container_name: ${CONTAINER_PREFIX}_app

db: image: postgres restart: always volumes: - /var/lib/postgresql/data environment: POSTGRES_DB: $DB_DATABASE POSTGRES_USER: $DB_USERNAME POSTGRES_PASSWORD: $DB_PASSWORD ports: - "5432:5432" container_name: ${CONTAINER_PREFIX}_db

`

I added the directive client_max_body_size 500M; But now instead of my site I get Unable to connect

Upvotes: 0

Views: 109

Answers (1)

Sergej Tihonov
Sergej Tihonov

Reputation: 241

client_max_body_size 500M;

must be inside the server tag

server {
...

client_max_body_size 500M;

...
}

Upvotes: 0

Related Questions