linux使用docker部署nginx
安装nginx
docker pull nginx
绑定端口和映射路径
1 | docker run -d -p 80:80 -p 81:81 -p 82:82 --name nginx\ |
nginx配置模板
nginx.conf配置选项
1 | user www-data; |
conf.d下的文件配置模板
反向代理其他端口的服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46server {
listen 80;
server_name zfxt.top;
add_header Strict-Transport-Security max-age=15768000;
return 301 https://$server_name$request_uri;
location / {
# 单个服务
proxy_pass http://127.0.0.1:5244/;
# 负载均衡
# proxy_pass http://yourServers/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
}
}
server {
listen 443 ssl;
server_name zfxt.top;
# 下面ssl开头的是HTTPS相关的设置
ssl on;
ssl_certificate /root/.acme.sh/*.zfxt.top_ecc/fullchain.cer;
ssl_certificate_key /root/.acme.sh/*.zfxt.top_ecc/*.zfxt.top.key;
ssl_session_timeout 3600m;#session有效期,根据需要适当延长
ssl_session_cache shared:SSL:10m;
# 使用的加解密方式
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
# 支持的协议类型
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# 优先使用服务端的加解密方式
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
proxy_redirect off;
proxy_pass http://127.0.0.1:5244;
# the max size of file to upload
client_max_body_size 20000m;
}
}或者直接启动前端服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50server {
listen 80;
server_name zfxt.top;
rewrite ^(.*)$ https://$host$1 permanent;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html;
}
}
server {
listen 443 ssl;
server_name zfxt.top;
ssl on;
ssl_certificate /root/.acme.sh/zfxt.top_ecc/fullchain.cer;
ssl_certificate_key /root/.acme.sh/zfxt.top_ecc/zfxt.top.key;
ssl_session_timeout 3600m;#session有效期,根据需要适当延长
ssl_session_cache shared:SSL:10m;
root /etc/nginx/conf.d/typecho;
index index.php;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#typecho
location ~ .*\.php(\/.*)*$ {
root /etc/nginx/conf.d/typecho/;
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#location / {
#root /etc/nginx/conf.d/typecho;
#index index.html index.php;
#}
location /sentence {
proxy_pass http://localhost:8080/api/sentence;
}
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 小贺同学的blog!
评论