nginx安装SSL证书

默认已经安装好了nginx

准备SSL证书

阿里云,腾讯云有免费的SSL证书当然你也能用收费的

配置
  • 创建目录
mkdir ssl #证书目录
mkdir vhost #配置目录
  • 修改nginx.conf配置
 http{
  #在http模块里添加:
	include vhost/*.conf;#匹配vhost目录下的所有.conf文件
}
  • 在vhost目录添加配置

配置文件名一般为 域名.conf, 我的配置文件名是 wx.host.com.conf

server {
    listen 443 ssl;
    server_name wx.host.com;
		#日志位置
    access_log  /var/log/nginx/wx.shqunqiu.https.access.log;

    # ssl 证书位置;
    ssl_certificate      ssl/wx.shqunqiu.com.pem;
    ssl_certificate_key  ssl/wx.shqunqiu.com.key;

	location  / {
		try_files $uri $uri/ /index.html;
		root /opt/app_static/wechat;
	}

	location /wechat {
		client_max_body_size 5m;
		proxy_pass http://127.0.0.1:10233/wechat;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
	}
  
 }


server {
	listen 80;
	server_name wx.host.com;	
  location / {
    	# 重定向到 https请求
      return 301 https://$server_name$request_uri;
  }
}

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐