Skip to content

Commit

Permalink
ci(nginx): add nginx expose port 443
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang Li committed Jul 23, 2024
1 parent d11306e commit 43f46a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
envs: IMAGE,CONTAINER
script:
script: |
docker pull $IMAGE
docker stop $CONTAINER || true
docker rm $CONTAINER || true
docker run -d --name $CONTAINER -p 80:80 $IMAGE
docker run -d --name $CONTAINER -p 80:80 -p 443:443 -v /data/nginx-certs:/etc/nginx/certs $IMAGE
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ RUN pnpm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
66 changes: 30 additions & 36 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
#nginx进程数,通常设置成和cpu的数量相等
worker_processes auto;

#参考事件模型
events {
#单个进程最大连接数(最大连接数=连接数+进程数)
worker_connections 1024;
}

#设定http服务器
http {
#文件扩展名与文件类型映射表
include mime.types;

#默认文件类型
default_type application/octet-stream;

#虚拟主机的配置
server {
#监听端口
listen 80;
#域名可以有多个,用空格隔开
server_name promonkeyli.top;
# http => https
# return 301 https://$host$request_uri;
http => https
return 301 https://$host$request_uri;

#定义本虚拟主机的访问日志
#access_log /admin-fe-access.log main; # 注意,在 Dockerfile 中创建 /admin-fe-access.log

#入口文件的设置
location / {
root /usr/share/nginx/html; #入口文件的所在目录
index index.html index.htm; #默认入口文件名称
try_files $uri $uri.html $uri/ =404;
}
# location / {
# root /usr/share/nginx/html; #入口文件的所在目录
# index index.html index.htm; #默认入口文件名称
# try_files $uri $uri.html $uri/ =404;
# }
# error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
Expand All @@ -44,29 +40,27 @@ http {
}

# https 配置
# server {
# #SSL 默认访问端口号为 443
# listen 443 ssl;
# #请填写绑定证书的域名
# server_name promonkeyli.top;
# #请填写证书文件的相对路径或绝对路径
# ssl_certificate /etc/nginx/certs/promonkeyli.top_bundle.crt;
# #请填写私钥文件的相对路径或绝对路径
# ssl_certificate_key /etc/nginx/certs/promonkeyli.top.key;
# ssl_session_timeout 5m;
# #请按照以下协议配置
# ssl_protocols TLSv1.2 TLSv1.3;
# #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
# ssl_prefer_server_ciphers on;
# location / {
# #网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
# #例如,您的网站主页在 Nginx 服务器的 /etc/www 目录下,则请修改 root 后面的 html 为 /etc/www。
# root /usr/share/nginx/html; #入口文件的所在目录
# index index.html index.htm; #默认入口文件名称
# try_files $uri $uri.html $uri/ =404;
# }
# }
# }

server {
#SSL 默认访问端口号为 443
listen 443 ssl;
#请填写绑定证书的域名
server_name promonkeyli.top;
#请填写证书文件的相对路径或绝对路径
ssl_certificate /etc/nginx/certs/promonkeyli.top_bundle.crt;
#请填写私钥文件的相对路径或绝对路径
ssl_certificate_key /etc/nginx/certs/promonkeyli.top.key;
ssl_session_timeout 5m;
#请按照以下协议配置
ssl_protocols TLSv1.2 TLSv1.3;
#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
#例如,您的网站主页在 Nginx 服务器的 /etc/www 目录下,则请修改 root 后面的 html 为 /etc/www。
root /usr/share/nginx/html; #入口文件的所在目录
index index.html index.htm; #默认入口文件名称
try_files $uri $uri.html $uri/ =404;
}
}
}

0 comments on commit 43f46a8

Please sign in to comment.