将Nginx配置为服务HTTPS失败,但是可以通过HTTP服务工作

时间:2020-03-31 20:07:20

标签: reactjs nginx web

首先,我完全理解那里有很多反映该主题的文章。但是,我已经阅读并重新阅读了其中的许多内容,但仍然感到困惑。

我有一个非常简单的静态网页(这是一个Hello World HTML页面,但最终它将用于生产构建反应应用程序),我需要通过 Nginx 在< strong> HTTPS 。

我已经能够通过 HTTP 而不是 HTTPS 来存储HTML。

可以正常工作以通过 HTTP 提供服务的我的 Nginx 配置文件是:

server {
  listen 80; 

  server_name app.mycompany.com;
  root /opt/mycompany/mycompany-web/packages/client/build;
  index index.html;


  access_log /var/log/nginx/app.mycompany.com.access.log;
  error_log /var/log/nginx/app.mycompany.com.error.log debug;

  location / {
    try_files $uri /index.html =404;
  }
}

我的无法正常工作的 Nginx 配置文件可以通过 HTTP 进行投放,是:

server {
  listen [::]:443 ssl ipv6only=on;
  listen 443 ssl;

  server_name app.mycompany.com;
  root /opt/mycompany/mycompany-web/packages/client/build;
  index index.html;

  ssl_certificate /etc/letsencrypt/live/app.mycompany.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/app.mycompany.com/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

  access_log /var/log/nginx/app.mycompany.com.access.log;
  error_log /var/log/nginx/app.mycompany.com.error.log debug;

  location / {
    try_files $uri /index.html =404;
  }
}

使用第一个配置,我的网页可以正确显示,但是,使用第二个配置,我只会得到404。

从我在网上阅读的内容来看,以上内容看起来正确。

有人可以看到我可能要出问题的地方吗? 如何开始调试未通过HTTP提供的HTML?

更新(根据Timo Stark的评论)

curl进入https://localhost:443返回404:

# curl -ikv https://localhost:443
* Rebuilt URL to: https://localhost:443/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*    subject: CN=app.mycompany.com
*    start date: 2020-03-31 18:34:56 GMT
*    expire date: 2020-06-29 18:34:56 GMT
*    issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*    SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
Server: nginx/1.4.6 (Ubuntu)
< Date: Wed, 01 Apr 2020 00:02:16 GMT
Date: Wed, 01 Apr 2020 00:02:16 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 177
Content-Length: 177
< Connection: keep-alive
Connection: keep-alive

< 
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>
* Connection #0 to host localhost left intact

更新2

$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

我的 /etc/nginx/nginx.conf 文件是:

# cat /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

0 个答案:

没有答案
相关问题