配置

conf文件夹下 nginx.config


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;
     # 监听多个端口 如下
    server {
        listen       9000;
        listen  [::]:9000;
        server_name  localhost;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
        include /etc/nginx/conf.d/*.conf;

    }
    
    server {
        listen       19004;
        listen  [::]:19004;
        server_name  localhost;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
        include /etc/nginx/conf.d/report/*.conf;

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

conf.d文件夹下前台路由

location /pw {
    alias  /app/html/路径1/路径2/dist;
    index  index.html index.htm;
    try_files $uri $uri/ /pw/index.html;
}


location /pw/assistant/ {
 # 后端访问前缀
	proxy_pass http://后端ip:8090/prefix/;
	  proxy_set_header Host $host;  	
}

Dokcerfile

from nginx:latest
workdir /usr/share/nginx/html
#RUN rm -f /docker-entrypoint.sh && rm -fr /usr/share/nginx/html/* && rm /etc/nginx/conf.d/*
copy html/  .
copy conf/ /usr/share/nginx/conf
copy conf.d/  /usr/share/nginx/conf.d
copy conf/nginx.conf /etc/nginx/nginx.conf
copy conf.d /etc/nginx/conf.d
copy html/ /app/html
expose 9000
cmd ["nginx","-g","daemon off;"]

备注

在这里插入图片描述

更多推荐