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 /home/nginx/html/dist;
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:/home/nginx/html/dist -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro --name nginx nginx
注意:如果出现权限问题或者打开nginx访问异常,需要设置前端文件全部授权权限(重启)
麒麟系统版本:
Kylin 4.19.90-52.30.v2207.ky10.x86_64
docker版本:
18(稳定)
23.0.6
问题记录:
前端页面能打开,代理对的,后端接口404
nginx替换新前端代码包得赋权 chmod 777 文件夹名称
解决以下问题:
3-1:代理地址都对没改动,接报404
3-2:docker nginx 502错误 connect() failed (111: Connection refused) while connecting to upstream
重启docker程序,然后启动容器内程序,检查前端能否正常请求过去,如果不行那就重启麒麟系统
4:可以进入nginx容器
docker exec -it nginx /bin/sh
5:在nginx容器里面可以检测nginx配置文件和重载文件
nginx -t
nginx -s reload