docker 运行镜像(在容器里面的html映射 错误导致我找了一整天,难受)
docker 运行镜像(nginx/1.19.6)
1.先在Linux宿主机上 创建文件夹usr/location/nginx
2.分别 创建下列对应的 2个文件(nginx.conf和default.conf)和2个目录
docker run -id --name nginx01 \
-p 8081:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf\
-v $PWD/conf/default.conf:/etc/nginx/conf.d/default.conf\
-v $PWD/logs:/var/log/nginx\
-v $PWD/html:/usr/share/nginx/html\
nginx
进入docker容器内部
docker exec -it 1e6275708960 bin/bash
docker容器向本机传送文件
docker cp container_id:docker容器内的文件全路径 本机保存文件的全路径
例如:docker cp 4a2f08d2c1f8:/data1/configure.txt E:\PHP\configure.txt
本机向docker容器传送文件
docker cp 本机保存文件的全路径 container_id:docker容器内的文件全路径
例如:docker cp E:\PHP\configure.txt 4a2f08d2c1f8:/data1/configure.txt
@!!!!!Nginx配置完成后为什么没有反向代理成功呢!!!!!@
首先,这里面配置的IP就错了,为什么呢?
因为我的这个nginx是放在Docker 容器中的,虽然将容器挂载的 数据卷持久化在 宿主机,localhost就是访问当前的容器,但是我的tomcat是放在其他的容器中,互不干扰影响,所有 我们需要将 IP 填 Linux宿主机的 内网地址
default.conf 模板
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~* /edu/ {
proxy_pass http://mytomcat;
}
location ~* /edu2/ {
proxy_pass http://172.19.35.105:8087;
}
location /www/ {
root /datas/;
index index.html;
}
location /images/ {
root /datas/;
autoindex on;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
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;
upstream mytomcat{
server 172.19.35.105:8086;
server 172.19.35.105:8087;
}
include /etc/nginx/conf.d/*.conf;
}