【发布时间】:2022-01-18 02:53:01
【问题描述】:
说明
我已经在 ubuntu 服务器上安装了 NGINX。它可以工作,我可以使用来自同一服务器的静态文件运行不同的网站。
现在安装 docker 并构建一个镜像,将其推送到这个 ubuntu 服务器并使用 docker 运行它。当我调用它server-ip:port 时,我可以使用静态文件访问该站点。
问题
我不知道,如何说 nginx 的静态文件在哪里。因为它们在 docker 容器内。
Nginx 配置
server {
index index.php index.html index.htm index.nginx-debian.html;
server_name sub.domain.com www.sub.domain.com;
root <------ what here?
location / {
proxy_pass http://localhost:7000;
}
proxy_set_header Host $http_host;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
charset utf-8;
# php fpm
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /favicon.ico {
allow all;
log_not_found off;
access_log off;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# basic cache control
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 30d;
add_header Cache-Control "public,max-age=31536000";
access_log off;
}
# svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
expires 30d;
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public,max-age=31536000";
access_log off;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
}
问题
安装在服务器上(不在 docker 容器内)的 Nginx 能否从 Docker 容器内的公共文件夹中提供静态文件?
【问题讨论】: