1.在/root目录下创建nginx目录用于存储nginx数据信息。
mkdir nginx
cd nginx
mkdir conf
cd conf
vim nginx.conf
2.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;
include /etc/nginx/conf.d/*.conf;
}
3.创建nginx容器
docker run -id --name=nginx \
-p 80:80 \
-p 81:81 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/conf.d:/etc/nginx/conf.d \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx
4.在~/nginx/ 导入打包后的后台的dist文件夹,重命名为manager;导入打包后的门户的dist文件夹,重命名为portal。然后将manager和portal拷贝到nginx容器的/usr/share/nginx目录。
5.在~/nginx/conf.d/下创建80.conf
server {
listen 80;
server_name manager.legou.com;
location / {
root /usr/share/nginx/manager;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
6.在~/nginx/conf.d/下创建81.conf
server {
listen 81;
server_name portal.legou.com;
location / {
root /usr/share/nginx/portal;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}