docker部署nginx

发布时间:2023年12月18日

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;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

server {
    listen 80; # 监听的端?
    server_name 121.46.30.191;# 域名或ip
    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;# 域名或ip
    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
文章来源:https://blog.csdn.net/qq_19891197/article/details/134944713
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。