nginx配置域名https

一、centos7安装nginx

1.上传nginx安装包至/tmp目录

下载nginx需要的依赖,先下载到服务器或虚拟机内

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

 2.解压nginx安装包至指定目录

cd /tmp

tar -zxvf nginx-1.16.1.tar.gz -C /usr/local

cd /usr/local

mkdir nginx

cd /usr/local/nginx-1.16.1

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make install

 说明:

nginx-1.16.1主要为源码安装

nginx为我们的主要使用,后面的配置都会在此文件夹中进行

二、nginx配置https

cd /usr/local/nginx/conf/

mkdir ssl

将域名证书上传至ssl文件夹下面,无论腾讯云还是华为云,只要你的域名备案完毕,都可以下载证书,我主要采用nginx需要的域名证书

1.配置nginx.conf

/usr/local/nginx/conf

vim nginx.conf

user  root;
worker_processes  auto;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}
http{
    server{
        listen 443 ssl;
        #对应你的域名
        server_name jpg.com;
        ssl_certificate /usr/local/nginx/conf/ssl/hjpg.com_server.crt;
        ssl_certificate_key /usr/local/nginx/conf/ssl/jpg.com_server.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        #如果是静态文件,直接指向目录,如果是动态应用,用proxy_pass转发一下
       # location / {
           #     root /usr/local/service/ROOT;
                #index index.html;
        #}
    }
    #监听80端口,并重定向到443
    server{
        listen 80;
        server_name jypxhjpg.com;
        rewrite ^/(.*)$ https://jpg.com:443/$1 permanent;
    }
}

2.启动或停止nginx

cd  /usr/local/nginx/conf
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

停止nginx的原则就是查出nginx对应的pid,然后kill -9 杀掉它

例如:

lsof -i:80

kill -9 pid


总结

nginx配置https,首先申请域名,一般管局审核在10天左右,申请下来后,再下载ssl证书,ssl证书我建议先使用免费版的,一般的ssl证书都支持nginx的。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
配置nginxhttps域名,你可以按照以下步骤进行操作: 1. 首先,确保你的域名已经备案,否则需要进行备案。你可以在浏览器中输入你的域名,如果出现网站未备案或者welcome to nginx的提示,说明你的域名https已经搭建完成,未备案的话需要进行备案。\[1\] 2. 在配置完成后,你需要重启nginx。你可以使用以下命令来操作: - 查看nginx的运行状态:systemctl status nginx - 启动nginx:systemctl start nginx - 关闭nginx:systemctl stop nginx - 重启nginx:systemctl restart nginx\[2\] 3. 进入nginx的sbin目录,使用以下命令启动nginx: - 进入sbin目录:cd /usr/local/nginx/sbin - 执行启动命令:./nginx - 停止nginx:./nginx -s stop - 重新加载nginx:./nginx -s reload\[3\] 通过以上步骤,你就可以成功配置nginxhttps域名了。 #### 引用[.reference_title] - *1* *2* [nginx部署https域名](https://blog.csdn.net/weixin_52994410/article/details/125671462)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [nginx配置https访问](https://blog.csdn.net/qd2013498006/article/details/122159653)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值