中沒有提供靜態內容,因爲它在一個「小」問題上浪費了幾乎整個星期日,因此我想尋求一些幫助。也許我已經監督了一個小錯誤。docker-container中的Nginx在Symfony3-app
我想開發一種基於的Symfony 3.爲了擁有苗條的開發環境的應用程序,我使用的碼頭工人與這三個容器:
- MySQL的(正常工作)
- PHP-FPM(定義爲在我的搬運工-compose.yml 「APP」)
- nginx的
這是搬運工/ nginx的/ MySQL的配置:
我搬運工-compose.yml:
version: '3.0'
services:
nginx:
image: nginx:latest
depends_on:
- app
ports:
- '8080:80'
volumes:
- ./app/config/docker/nginx.conf:/etc/nginx/conf.d/default.conf
app:
build: .
depends_on:
- mysql
volumes:
- .:/var/www/html
- vendor:/var/www/html/vendor
mysql:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
- ./app/config/docker/mysql_character_set.cnf:/etc/mysql/conf.d/character_set.cnf
restart: always
ports:
- '6603:3306'
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "test"
MYSQL_USER: "test"
MYSQL_PASSWORD: "test"
volumes:
db_data:
vendor:
我nginx.conf:
server {
listen 80 default_server;
root /var/www/html/web;
index app_dev.php app.php;
location/{
# try to serve file directly, fallback to app.php
try_files $uri /app_dev.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
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_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log error;
}
我Dockerfile:
FROM php:7.1-fpm
MAINTAINER [email protected]
ENV DEBIAN_FRONTEND=noninteractive
ENV PHP_DEPS="pdo pdo_mysql"
ADD . /var/www/html
# php extensions
RUN docker-php-ext-install $PHP_DEPS
# composer
RUN curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/local/bin --filename=composer && \
composer --version
# copy php-conf
COPY app/config/docker/fpm.conf /etc/php-fpm.d/autotrader.conf
CMD ["php-fpm"]
文檔根的 「LS」:
app.php
apple-touch-icon.png
config.php
image.png
robots.txt
app_dev.php
bundles
favicon.ico
navigation.css
此配置有以下問題:
當我在我的瀏覽器中打開「http://localhost:8080/」:(幾乎)一切正常:PHP正在運行並且頁面顯示(沒有錯誤可見)。 但什麼不工作:通過nginx提供像「navigation.css」這樣的靜態文件。 Chrome的web開發者工具欄,在Network-Tab中,我總是得到一個「404 Not Found」 - 「navigation.css」的消息。
當我在瀏覽器中直接調用http://localhost:8080/navigation.css時,Symfony發生錯誤:「找不到」GET /navigation.css「路由。
當我對此進行正確解釋時,這意味着,nginx無法找到「navigation.css」,並將此參數提供給Symfony(app_dev.php),並且框架正在尋找名爲「navigation」的路由。 css「,它不存在。
所以我的主要問題是:爲什麼nginx無法看到靜態文件?我的意思是,靜態文件和php文件(被提供)位於同一個目錄中。我真的不明白...希望有人能夠看到我的錯誤。
不客氣:)我很高興它的工作,你可以接受答案,並點擊向上箭頭嗎? @ User5518 – Sergiu
非常感謝!在「docker-compose.yml」中爲這個新的nginx卷配置工作: ' - 。/ web/static:/ var/www/html/web/static' – User5518
(我也將我的靜態文件移動到「web/static」) – User5518