安装nginx,配置https

nginx安装

下载nginx:下载地址

上传到/opt目录

解压nginx,并进入解压后到目录

bash 复制代码
cd /opt
tar -zxvf nginx-1.25.2.tar.gz
cd nginx-1.25.2

编译(with-http_ssl_module为https模块)

bash 复制代码
./configure --with-http_ssl_module

安装

bash 复制代码
make install

默认的安装目录为:/usr/local/nginx

  • 启动Nginx
bash 复制代码
./nginx
  • 重启Nginx
bash 复制代码
./nginx -s reload
  • 关闭Nginx
bash 复制代码
./nginx -s stop

生成https自签名证书,如果是公网域名,可以申请阿里云免费证书

创建证书目录,并进入该目录

bash 复制代码
mkdir /usr/local/nginx/cert
cd /usr/local/nginx/cert

生成私钥

bash 复制代码
openssl genrsa -out server.key 2048

生成公钥

bash 复制代码
openssl req -new -key server.key -out server.csr

生成证书

bash 复制代码
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

配置nginx https

bash 复制代码
vim /usr/local/nginx/conf/nginx.conf

添加以下内容

bash 复制代码
server {
        listen       443 ssl;
        server_name  localhost;

		# https证书
        ssl_certificate      /usr/local/nginx/cert/server.crt;
        ssl_certificate_key  /usr/local/nginx/cert/server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        # 代理地址
        location / {
           proxy_pass http://localhost:8848/;
        }
 }
相关推荐
马立杰1 小时前
H3CNE-33-BGP
运维·网络·h3cne
云空2 小时前
《DeepSeek 网页/API 性能异常(DeepSeek Web/API Degraded Performance):网络安全日志》
运维·人工智能·web安全·网络安全·开源·网络攻击模型·安全威胁分析
没有名字的小羊3 小时前
Cyber Security 101-Build Your Cyber Security Career-Security Principles(安全原则)
运维·网络·安全
千夜啊3 小时前
Nginx 运维开发高频面试题详解
运维·nginx·运维开发
存储服务专家StorageExpert4 小时前
答疑解惑:如何监控EMC unity存储系统磁盘重构rebuild进度
运维·unity·存储维护·emc存储
chian-ocean6 小时前
从理论到实践:Linux 进程替换与 exec 系列函数
linux·运维·服务器
敖行客 Allthinker6 小时前
从 UTC 日期时间字符串获取 Unix 时间戳:C 和 C++ 中的挑战与解决方案
linux·运维·服务器·c++
JunLan~7 小时前
Docker 部署 GLPI(IT 资产管理软件系统)
运维·docker·容器
慕雪华年9 小时前
【Linux】opencv在arm64上提示找不到libjasper-dev
linux·运维·opencv
_Eden_9 小时前
Keepalived高可用集群企业应用实例一
运维·服务器