1:拉取nginx镜像
docker pull nginx
2:注意nginx配置文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name 121.46.30.191;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router{
rewrite ^.*$ /index.html last;
}
location /qx/bi/ {
proxy_pass http://192.168.31.2:8001/qx/bi/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 801;
server_name 121.46.30.191;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router{
rewrite ^.*$ /index.html last;
}
location /qx/bi/ {
proxy_pass http://192.168.31.2:8001/qx/bi/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3:启动nginx容器(注意设置这个最好设置两个端口,避免默认端口80重复问题)
docker run -d -p 8000:80 -p 801:801 -v /home/nginx/html/dist:/opt/html -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro --name nginx nginx
4:可以进入nginx容器
docker exec -it nginx /bin/sh
4:在nginx容器里面可以检测nginx配置文件和重载文件
nginx -t
nginx -s reload