我有一个静态网站,我想根据浏览器语言创建重定向。该网站使用 nginx 在 docker 中运行,构建如下:
nginx.conf:
user nginx;
worker_processes 4;
error_log /dev/stderr info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /dev/stdout;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
root /usr/share/nginx/my-app;
map $http_accept_language $myindex {
default index.html;
~*^fr.* index.fr.html;
}
server {
location / {
rewrite .* $myindex;
}
}
}
默认.conf:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www;
index index.html;
location / {
try_files $uri $uri/ /index.html$is_args$args;
}
}
dockerfile
# nginx
FROM nginx:1.17.5-alpine
COPY src /var/www
COPY nginx.conf /etc/nginx/nginx.conf
COPY conf.d /etc/nginx/conf.d
EXPOSE 80
一旦我转到本地主机,就会出现以下问题:en -> index.html en -> index.html(预期:index.de.html)