我正在尝试在Docker中添加SSL。除了我的nodejs应用程序外,所有设置都已设置。
这是我的nginx配置
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
}
map $is_desktop $is_mobile {
1 0;
0 1;
}
server {
listen 443 ssl;
server_name example.com;
charset utf-8;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
}
access_log /usr/logs/nginx/lion/lion.$year-$month-$day.log;
ssl_certificate /etc/nginx/ssl/example.com/b2d6debd2142c643.crt;
ssl_certificate_key /etc/nginx/ssl/example.com/example.key;
location / {
index index.html;
if ($is_mobile) {
root /usr/src/lion;
}
if ($is_desktop) {
proxy_pass http://martinez:3000;
}
error_page 404 =301 /;
}
location /dist {
alias /usr/src/martinez/dist;
access_log off;
}
location /img {
if ($is_desktop) {
root /usr/src/martinez/dist;
access_log off;
}
}
error_page 405 =200 $uri;
}
server {
listen 443;
server_name www.example.com;
return 301 $scheme://$host$request_uri;
}
当我尝试访问此广告时,它会在网址栏上显示不安全,这可能是因为proxy_pass不在 https 中。当我尝试将其更改为 https 时,我得到 502 Bad Gateway ,我无法解决。我已经尝试过暴露并打开docker-compose.yml上的端口
搬运工-compose.yml
martinez:
restart: always
build: ./martinez/
expose:
- "3000"
- "443"
ports:
- "3000:443"
tty: true
env_file: .env
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
- "443:443"
- "3000:3000"
links:
- martinez:martinez