如何使用nginx

时间:2018-06-30 12:31:30

标签: node.js nginx https

我有一个运行在https://localhost:8080中的node.js应用程序,它具有localhost.crtlocalhost.key,我希望将nginx重定向到https://app.example.com的服务器(我已经安装了另一个证书在此子域上使用certbot)现在即时获取

  

未知ALPN协议,预期h2可用。如果这是HTTP请求:未为服务器配置allowHTTP1选项或unknownProtocol事件的侦听器。

在浏览器中,有人可以帮助我进行正确的Nginx服务器配置吗? Screenshot  我也在Ubuntu 16.04上使用Digitalocean Droplet来设置它 这是我设置的Nginx服务器。

server {
listen 80;
return 301 https://$host$request_uri;
}

server {

listen 443;
server_name app.mydomain.com;

ssl_certificate           /root/apps/app.mydomain.com/localhost.crt;
ssl_certificate_key       /root/apps/app.mydomain.com/localhost.key;

ssl on;
ssl_session_cache  builtin:1000  shared:SSL:10m;
ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;

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

location / {

  proxy_set_header        Host $host;
  proxy_set_header        X-Real-IP $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header        X-Forwarded-Proto $scheme;

  # Fix the “It appears that your reverse proxy set up is broken" error.
  proxy_pass          https://localhost:8080;
  proxy_read_timeout  90;

  proxy_redirect      https://localhost:8080 https://app.mydomain.com;
}
}

2 个答案:

答案 0 :(得分:-1)

此:

listen 443;

应该是这样

listen 443 ssl;

为什么要通过https将流量代理到127.0.0.1?似乎不必要

答案 1 :(得分:-1)

尝试此配置,希望它能起作用。并非所有标头都是必需的,它取决于您的应用程序需求以及如何为应用程序处理请求。

server {
listen 80;
return 301 https://$host$request_uri;
}

server {
listen 443;
server_name app.mydomain.com;

ssl on;
ssl_certificate_key       /root/apps/app.mydomain.com/localhost.key;
ssl_certificate           /root/apps/app.mydomain.com/localhost.crt;
ssl_session_cache  builtin:1000  shared:SSL:10m;
ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;

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

location / {
    proxy_set_header        Host $host;
    proxy_pass          http://localhost:8080/;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_read_timeout  90;
    proxy_buffer_size   128k;
    proxy_buffers   4 256k; 
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    proxy_connect_timeout 300s;
}
}