【阿里云服务器部署node项目(七)】服务器上https的配置

其他关于服务器的配置可查看我的其他文章

1、进入控制台-SSL证书

在这里插入图片描述

2、选择购买证书

在这里插入图片描述

3、选择一种购买,我选择的是免费

在这里插入图片描述

4、购买完成后返回“证书控制台”申请并补全信息,等待审核,审核成功后

在这里插入图片描述

5、nginx配置-下载

在这里插入图片描述
下载后得到如图两个文件
在这里插入图片描述

6、将这两个文件上传到服务器 /jane-soft/https/目录
7、然后配置nginx.conf ,官网教程

//通过在linux上 nginx -t 查看该文件所在目录

8、附录

在这里插入图片描述

  • nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

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

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       8080 ssl;
        server_name  localhost;
        root         /jane-code/clock-out/dist;

        ssl_certificate      /jane-soft/https/2426128_www.zhangxiaojuan.club.pem;
        ssl_certificate_key  /jane-soft/https/2426128_www.zhangxiaojuan.club.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

	    location /api/ {
                proxy_pass http://localhost:4000/api/;
        }

        location / {
       		try_files $uri $uri/ @router;
		index  index.html index.htm;
	    }

        location @router{
            rewrite ^.*$/index.html last;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

        server {
            listen       8081 ssl;
            server_name  localhost;
            root         /jane-code/clock-out/visitor/dist;

            ssl_certificate      /jane-soft/https/2426128_www.zhangxiaojuan.club.pem;
            ssl_certificate_key  /jane-soft/https/2426128_www.zhangxiaojuan.club.key;

            ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  5m;

            ssl_ciphers  HIGH:!aNULL:!MD5;
            ssl_prefer_server_ciphers  on;

            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;

    	    location /api/ {
                    proxy_pass http://localhost:4001/api/;
            }

            location / {
           		try_files $uri $uri/ @router;
    		index  index.html index.htm;
    	    }

    	    location @router{
    		    rewrite ^.*$/index.html last;
    	    }

            error_page 404 /404.html;
                location = /40x.html {
            }

            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
        }





}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将Node.js项目部署到阿里云服务器(centos),您可以按照以下步骤进行操作: 1. 首先,登录到您的阿里云服务器。您可以使用SSH客户端(如PuTTY)连接到服务器。 2. 在服务器上安装Node.js。您可以使用Node.js官方网站提供的安装包进行安装,也可以使用包管理工具(如yum)进行安装。 3. 检查Node.js是否成功安装。通过运行命令`node -v`和`npm -v`分别检查Node.js和npm的版本号,确保它们都已安装成功。 4. 在服务器上创建一个目录来存储您的Node.js项目文件。您可以选择在默认的`/var/www/html/`目录下创建一个新目录,或者根据您的需求选择其他位置。 5. 将您的Node.js项目文件上传到服务器的目录中。您可以使用FTP客户端(如FileZilla)将项目文件上传到服务器,或者通过git命令将文件从本地仓库推送到服务器上。 6. 在服务器上安装项目所需的依赖。在项目文件的根目录下,运行`npm install`命令安装项目的依赖模块。 7. 使用PM2进程管理工具来启动Node.js应用程序。运行`npm install -g pm2`命令来全局安装PM2,然后使用`pm2 start app.js`命令启动您的Node.js应用程序。 8. 配置防火墙规则以允许对Node.js应用程序的访问。您可以在阿里云控制台中配置安全组规则,确保服务器的80端口(或您的Node.js应用程序使用的任何其他端口)是开放的。 9. 进行域名解析(可选)。如果您有一个域名,您可以将其解析到服务器的IP地址上,以便用户可以通过域名访问您的Node.js应用程序。 通过以上步骤,您的Node.js项目将成功部署到阿里云服务器上,并可以通过服务器的IP地址或域名进行访问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值