首页 > 解决方案 > Nginx 上 HTTPS 请求的内部服务器错误

问题描述

我在 docker 中使用 nginx,我的 nginx.conf 文件如下:

server {
    listen       80;
    server_name  localhost;
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    location / {
        try_files $uri $uri/ /index.html$is_args$args;
    }
    location /web {
            alias   /usr/share/nginx/html;
            index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
server {
    listen 443;
    ssl on;
    ssl_certificate /etc/ssl/nginx.crt;
    ssl_certificate_key /etc/ssl/nginx.key;
    server_name localhost;
    server_tokens off;
    location / {
        try_files $uri $uri/ /index.html$is_args$args;
    }
    location /web {
            alias   /usr/share/nginx/html;
            index  index.html index.htm;
    }

    #location / {
    #    root   /usr/share/nginx/html;
    #    index  index.html index.htm;
    #}
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

当我通过 http 加载我的网站时,我没有任何问题,但是当我通过 https 加载时,它给了我一个内部服务器错误,同时它表明连接是安全的

500 Internal Server Error
      nginx

谁能指出我的配置有什么问题。

我还附上了我用来使 Nginx 工作的 Dockerfile

# build environment
FROM node:14.17.1 as builder
#more commands

# production environment
FROM nginx:stable-alpine
COPY --from=builder /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
COPY nginx.crt /etc/ssl/
COPY nginx.key /etc/ssl
EXPOSE 80
EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]

谢谢你的帮助

标签: dockernginxhttps

解决方案


推荐阅读