Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用ssl在同一域名上运行api和网站_Node.js_Ssl_Nginx_Https_Lets Encrypt - Fatal编程技术网

Node.js 如何使用ssl在同一域名上运行api和网站

Node.js 如何使用ssl在同一域名上运行api和网站,node.js,ssl,nginx,https,lets-encrypt,Node.js,Ssl,Nginx,Https,Lets Encrypt,我有以下网站nepherius.xyz,我想运行一个常规域和一个使用相同名称的API,比如: -这将是常规网页 -这就是api 当前nginx.conf,大部分由letsencrypt的certbot生成 server { root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html;

我有以下网站nepherius.xyz,我想运行一个常规域和一个使用相同名称的API,比如:

-这将是常规网页 -这就是api

当前nginx.conf,大部分由letsencrypt的certbot生成

server {

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name nepherius.xyz www.nepherius.xyz_;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        proxy_pass http://localhost:8433;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/nepherius.xyz/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/nepherius.xyz/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
    if ($host = nepherius.xyz) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 default_server;

    server_name nepherius.xyz www.nepherius.xyz_;
    return 404; # managed by Certbot


}
server {
    if ($host = www.nepherius.xyz) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 ;
    server_name www.nepherius.xyz;
    return 404; # managed by Certbot

}
现在API可以正常工作,但如果我删除

    proxy_pass http://localhost:8433;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;

然后,常规站点可以工作,但API不能。那么我如何使这两个都工作呢?

尝试创建两个服务器,例如:

server {
    listen       80;
    server_name  www.nepherius.xyz;
    ...
}

server {
    listen       8433;
    server_name  www.nepherius.xyz;
    ...
}
这些将有助于在不同的端口中使用您的域