jenkins服务器IP假设为127.0.0.1
Nginx服务器IP假设为127.0.0.2
jenkins服务器与Nginx服务器实现免密登录
ssh -o StrictHostKeyChecking=no root@127.0.0.2 "docker pull 127.0.0.1:8082/fe/nginx-fe-$timestamp && \
docker stop jenkins-prod && \
docker rm jenkins-prod && \
docker run -p 8008:8008 -itd \
-v /home/nginx_prod:/etc/nginx \
--name jenkins-prod \
--restart always \
127.0.0.1:8082/fe/nginx-fe-$timestamp"
Nginx服务器配置信息处理
docker cp nginx容器ID:/etc/nginx/ /home/copy_test
docker cp 09719ff5d424:/etc/nginx/ /home/copy_test
nginx 目录展示
conf.d fastcgi.conf fastcgi.conf.default fastcgi_params fastcgi_params.default koi-utf koi-win mime.types mime.types.default nginx.conf
nginx.conf 可百度个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;
keepalive_timeout 65;
gzip on;
include /etc/nginx/conf.d/*.conf;
client_max_body_size 10m;
client_header_buffer_size 512k;
large_client_header_buffers 4 512k;
server {
listen 8004;
server_name 127.0.0.1:8004;
root /usr/share/nginx/html;
index index.html;
location /api {
proxy_pass http://127.0.0.1:8888/api;
proxy_redirect default;
proxy_set_header Host $proxy_host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
try_files $uri /index.html;
add_header Cache-Control "no-cache";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
前端项目根目录下配置Dockerfile文件
FROM nginx:1.15-alpine
COPY dist /usr/share/nginx/html
WORKDIR /usr/share/nginx/html
jenkins服务器 查看对应的前端资源
docker exec -it jenkins /bin/bash
cd /var/jenkins_home/worksapce
cd fe-prod
ls
Dockerfile README.md config debug.log dist node_modules package-lock.json
package.json postcss.config.js public src tsconfig.json
进入nginx容器的指令
docker exec -it 容器名称 /bin/sh
docker exec -it jenkins-nginx /bin/sh
|