【发布时间】:2021-01-22 20:55:46
【问题描述】:
我正在使用以下 docker 命令:
docker run --name spa \
-v "$PWD/build":/usr/share/nginx/html:ro \
-v "$PWD/nginx.conf":/etc/nginx/nginx.conf:ro -d -p 8080:80 nginx
然后我可以打开 localhost:8080 并获取索引,单击链接可以工作,因为导航是在客户端上完成的,但是然后刷新 localhost:8080/en 会给我一个来自 nginx 的 404。 "$PWD/nginx.conf" 是:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
root /usr/share/nginx/html;
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_comp_level 9;
etag on;
location / {
try_files $uri $uri/ /index.html;
}
location /static/ {
add_header Cache-Control max-age=31536000;
}
location /index.html {
add_header Cache-Control no-cache;
}
location /config.json {
add_header Cache-Control no-cache;
}
}
}
我得到了服务器部分表单here 并根据documentation 猜测它进入http,但是当路由不指向文件时它不服务器index.html。
在./build 中有一个文件index.html 在根路径上提供。
【问题讨论】:
标签: docker nginx single-page-application