Linux nginx docker,如何更改公共路径?
我想用docker配置nginx。 我的网站结构类似于:Linux nginx docker,如何更改公共路径?,linux,docker,nginx,web,Linux,Docker,Nginx,Web,我想用docker配置nginx。 我的网站结构类似于: root ..controller/phpFile1.php ..controller/phpFile2.php ..controller/phpFileN.php ..public/index.php ..public/css/file.css .. and so on 我已经阅读了各种推荐此类配置的指南: version: '3.6' services: my-app: image: nginx restart:
root
..controller/phpFile1.php
..controller/phpFile2.php
..controller/phpFileN.php
..public/index.php
..public/css/file.css
.. and so on
我已经阅读了各种推荐此类配置的指南:
version: '3.6'
services:
my-app:
image: nginx
restart: always
volumes:
- "/path/to/public:/usr/share/nginx/html"
environment:
# NGINX-PROXY ENVIRONMENT VARIABLES: UPDATE ME
- VIRTUAL_HOST=your-website-one.com
- VIRTUAL_PORT=80
- LETSENCRYPT_HOST=your-website-one.com
- LETSENCRYPT_EMAIL=your.email@domain.com
# /END NGINX-PROXY ENVIRONMENT VARIABLES
expose:
- 80
networks:
default:
external:
name: nginx-proxy
但是。。
我应该做的是链接docker中的site文件夹,并指定公用文件夹的路径。
我怎么做?在docker-compose.yml中:
创建块:
nginx:
container_name: nginx
image: nginx:latest
env_file:
- .env # If any environment variables used, place them in .env
ports:
- 80:80
- 443:443
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d # This maps nginx config volume
- ./public:/public # This maps your local public directory volume
现在,在同一级别中,创建一个目录
./config/nginx/config.d
并在该级别上放置一个文件local.conf,以便
./config/nginx/config.d/local.conf
随映像提供的deafolt nginx.conf将读取任何.conf文件
除非你覆盖它,这在你的情况下是不需要的
在/config/nginx/conf.d/local.conf
中添加或编辑指定
您所需的根位置:
server {
root /public; # That location corresponds to one mapped in docker-compose.yml
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
rewrite ^([^.]*[^/])$ $1/ permanent;
try_files $uri $uri/ /index.php =404;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
location ~ \.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff|css|js|xml|txt)$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
location ~ \.(?:swf|pdf|mov|fla|zip|rar|doc|docx|docm)$ {
try_files $uri =404;
}
}
这只是一个示例服务器块,您必须调整您的需要,指定所需的根位置、服务器名称和其他位置。
在本例中,我假设您的
/public
目录位于同一级别-如果它位于目录树中的更高级别或更低级别,则需要调整它,使其与docker-compose.yml的位置以及docker-compose.yml的nginx
配置块中提供的配置相对应。Ty!我试试看!