嘿,我正在try 使用symfony、docker和nginx部署我的第一个应用程序.目前,我只try 在本地运行我的停靠容器,但当我打开index.php时,它显示找不到我的*.css
和*.js
文件,并且出现404错误.另外,index.php正在工作,因为当我将默认的symfony index.php更改为echo "something"
时,它可以工作.我使用webpack安可来构建我的js和css文件,
Docker-compose.prod.yml
services:
# nginx
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
app:
build:
dockerfile: ./php/文档文件
volumes:
- /var/www/html/vendor
- .:/var/www/html
文档文件
FROM php:8.1-fpm-alpine
RUN apk update
RUN apk add vim
# install php with pgsql
RUN set -ex \
&& apk --no-cache add \
postgresql-dev
RUN docker-php-ext-install pdo pdo_pgsql pgsql
ENV COMPOSER_ALLOW_SUPERUSER=1
# get composer using multi-stage build
COPY --from=composer:2.4 /usr/bin/composer /usr/bin/composer
# copy composer.lock and composer.json
COPY ./composer.* ./
# install bundles from composer.json with options for deployment
RUN composer install --prefer-dist --no-dev --no-scripts --no-progress --no-interaction
# copy application files to default directory
COPY . .
# run composer dump-autload
RUN composer dump-autoload --optimize
Nginx的default.conf
server {
listen 80;
server_name localhost;
root /var/www/html/public;
index index.php;
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
文件 struct
app
│ composer.json
│ composer.lock
│ Docker-compose.prod.yml
│ package-lock.json
│ package.json
│ webpack.config.js
│
├───nginx
│ └───conf.d
│ default.conf
├───php
│ 文档文件
│
├───public
│ │ .htaccess
│ │ index.php
│ │
│ └───build
│ 500.c01022e5.js
│ app.90dc63d1.js
│ app.c6fd8b2d.css
│ entrypoints.json
│ manifest.json
│ runtime.61b1725c.js
这些是我打开localhost:80
时收到的错误
GET http://localhost/build/runtime.61b1725c.js net::ERR_ABORTED 404 (Not Found)
GET http://localhost/build/app.c6fd8b2d.css net::ERR_ABORTED 404 (Not Found)
GET http://localhost/build/app.90dc63d1.js net::ERR_ABORTED 404 (Not Found)
GET http://localhost/build/500.c01022e5.js net::ERR_ABORTED 404 (Not Found)