我使用以下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;
}
}
}
我得到了服务器部分的形式在这里,我猜它是在http根据文档,但它不server index.html当路由不指向一个文件。
在./build
中有一个文件index.html
被服务于根路径。
我在配置中删除了include /etc/nginx/conf.d/*.conf;
,现在它工作了。