Skip to content

Commit d0f0669

Browse files
committed
Refactor Dockerfile to copy nginx.conf and update entrypoint.sh
1 parent 84b91ab commit d0f0669

File tree

5 files changed

+126
-2
lines changed

5 files changed

+126
-2
lines changed

Framework/nginx/1.22.1/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN cd /home/devbox/project
55
RUN apt-get update && apt-get install -y nginx
66

77
COPY /Framework/nginx/1.22.1/project /home/devbox/project
8+
COPY /Framework/nginx/1.22.1/nginx.conf /etc/nginx/nginx.conf
89
RUN chown -R devbox:devbox /home/devbox/project && \
910
chmod -R u+rw /home/devbox/project && \
1011
chmod -R +x /home/devbox/project/entrypoint.sh

Framework/nginx/1.22.1/nginx.conf

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# /home/devbox/project/nginx.conf
2+
3+
user www-data;
4+
worker_processes auto;
5+
pid /run/nginx.pid;
6+
error_log /var/log/nginx/error.log warn;
7+
include /etc/nginx/modules-enabled/*.conf;
8+
9+
events {
10+
worker_connections 768;
11+
# multi_accept on;
12+
}
13+
14+
http {
15+
16+
##
17+
# Basic Settings
18+
##
19+
20+
sendfile on;
21+
tcp_nopush on;
22+
tcp_nodelay on;
23+
keepalive_timeout 65;
24+
types_hash_max_size 2048;
25+
# server_tokens off;
26+
27+
# server_names_hash_bucket_size 64;
28+
# server_name_in_redirect off;
29+
30+
include /etc/nginx/mime.types;
31+
default_type application/octet-stream;
32+
33+
##
34+
# SSL Settings
35+
##
36+
37+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
38+
ssl_prefer_server_ciphers on;
39+
40+
##
41+
# Logging Settings
42+
##
43+
44+
access_log /var/log/nginx/access.log;
45+
46+
##
47+
# Gzip Settings
48+
##
49+
50+
gzip on;
51+
52+
# gzip_vary on;
53+
# gzip_proxied any;
54+
# gzip_comp_level 6;
55+
# gzip_buffers 16 8k;
56+
# gzip_http_version 1.1;
57+
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
58+
59+
##
60+
# Virtual Host Configs
61+
##
62+
63+
include /etc/nginx/conf.d/*.conf;
64+
include /etc/nginx/sites-enabled/*;
65+
include /home/devbox/project/*.conf;
66+
}
67+
68+
#mail {
69+
# # See sample authentication script at:
70+
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
71+
#
72+
# # auth_http localhost/auth.php;
73+
# # pop3_capabilities "TOP" "USER";
74+
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
75+
#
76+
# server {
77+
# listen localhost:110;
78+
# protocol pop3;
79+
# proxy on;
80+
# }
81+
#
82+
# server {
83+
# listen localhost:143;
84+
# protocol imap;
85+
# proxy on;
86+
# }
87+
#}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
#!bin/bash
2-
sleep infinity
1+
#!/bin/bash
2+
# 确保脚本在出错时退出
3+
set -e
4+
5+
# 检查 nginx 配置是否正确
6+
nginx -t
7+
8+
# 前台启动 nginx(这样可以保持容器运行)
9+
exec nginx -g 'daemon off;'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="zh">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>欢迎使用 Nginx</title>
7+
</head>
8+
<body>
9+
<h1>欢迎使用 Nginx!</h1>
10+
<p>这是一个简单的 HTML 页面。</p>
11+
</body>
12+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
server {
2+
listen 8080; # 监听 8080 端口
3+
server_name _; # 匹配所有服务器名称
4+
5+
root /home/devbox/project; # 网站根目录
6+
index index.html; # 默认索引文件
7+
8+
location / {
9+
try_files $uri $uri/ /index.html; # 尝试返回 index.html
10+
}
11+
12+
# 可选:添加错误页面处理
13+
error_page 404 /404.html;
14+
location = /404.html {
15+
internal;
16+
}
17+
}

0 commit comments

Comments
 (0)