我正在用Symfony4和VueJs构建一个项目,该项目由nginx服务器托管并与Docker一起运行。我的模板还可以,但是css和js文件在404中。
这是我的Nginx配置:
Main
我配置了我的webpack文件:
server {
listen 80;
listen [::]:80;
server_name symfony.local;
root /var/www/myproject/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/(index)\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
Css和JS文件位于目录var Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
.addEntry('app', './assets/js/app.js')
.enableBuildNotifications()
.enableSassLoader()
.enableVueLoader();
;
module.exports = Encore.getWebpackConfig();
和assets\js\*
中,当我使用assets\css\*
进行编译时,我构建的文件位于yarn encore dev
和public\build\app.js
中
在模板base.html.twig中:
public\build\app.css
和
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}
文件也被编译,但是app.js和app.css出现错误404。 我已经像在https://symfony.com/doc/current/frontend.html中进行了解释 所以我不明白缺少了什么。
谢谢:)
答案 0 :(得分:1)
问题已解决,它在docker-compose.yml中: 在容器nginx中,我忘记了批量安装我的应用程序的路径,它仅适用于PHP容器
nginx:
image: nginx:latest
container_name: dso_nginx
hostname: nginx
ports:
- 80:80
- 443:443
depends_on:
- php
volumes:
- ./docker/nginx/default.template:/etc/nginx/conf.d/default.template
- ".:/var/www/my-symfony-project:ro"
- ./logs/nginx/:/var/log/nginx
env_file:
- .env
environment:
- NGINX_HOST=${NGINX_HOST}
command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"