我正在使用docker-compose在Nginx上运行django应用。
我还使用traefik作为反向代理来访问Django应用。
我正在尝试使用以下配置访问https://localhost/myapp上的应用程序。
nginx:
command: nginx -c /etc/nginx/nginx.conf
image: nginx:1.15-alpine
deploy:
labels:
traefik.port: 8080
traefik.frontend.entryPoints: https
traefik.frontend.rule: PathPrefixStrip:/myapp
但是我看不到CSS和JS正确加载。
控制台日志显示,静态页面应该位于/ static而不是/ myapp / static。
https://localhost/static/js/jquery-3.3.1.min.js 404
https://localhost/myapp/static/js/jquery-3.3.1.min.js 200
以下是我的nginx.conf
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 8080;
access_log off;
location /static/ {
alias /app/myapp/static/;
}
location / {
proxy_pass http://django-app:8001;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
}
我试图重写位置,但仍然无法正常工作。