404通过docker nginx提供静态文件

时间:2017-02-04 11:32:42

标签: nginx docker

我根据最新的官方图片构建了一个新的docker容器。

除了通过nginx提供静态文件外,一切正常。

我想这可能是服务器块文件中的错误,但这是在非docker环境中正常工作的配置。

如多个答案中所述,我已在位置/ {...}下包含mime-types。这也没有解决我的问题。

以下是我的配置:

搬运工-compose.yml

version: "2"
services:
    nginx:
        image: nginx:1.11
        ports:
            - "7200:80"
        volumes:
            - "./docker/nginx:/etc/nginx/conf.d"
            - "./docker/nginx/logs:/var/log/nginx"
            - ".:/var/www"
    php:
        build: ./docker/php/
        volumes:
            - ".:/var/www/html/"
    node:
        image: node:7.5
        volumes_from:
            - php
        working_dir: "/var/www/html/assets/"
    composer:
        image: composer:1.1
        volumes_from:
            - php
        working_dir: "/var/www/html/"
    mysql:
        image: mysql:latest
        environment:
            MYSQL_ROOT_PASSWORD: root
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        ports:
            - "7201:80"
        links:
            - mysql
        environment:
            PMA_HOST: mysql

default.conf(项目的服务器块)

server {
    listen 80 default_server;
    root /var/www/html/public;
    index index.php index.html;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    charset utf-8;

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

    # Block access to .htaccess
    location ~ \.htaccess {
       deny all;
    }

    location ~ \.php(?:/.+)?$ {
        rewrite ^(.+.php)(?:/(.+))$ $1?request=$2 break;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param APPLICATION_ENV development;

        fastcgi_buffer_size 256k;
        fastcgi_buffers 8 512k;
        include fastcgi_params;
    }

    location = /assets/img/favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }
    location ~ /.well-known { allow all; }
    location ~ /\. { deny all; access_log off; log_not_found off; }

    sendfile off;
    client_max_body_size 100m;
}

感谢您的每一个答案/建议。

0 个答案:

没有答案
相关问题