Nginx从搭建到配置支持HTTPS的方法
发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,安装基础包ububtuapt-get install build-essentialapt-get install libtoolcentosyum -y install gcc automake a
千家信息网最后更新 2025年02月07日Nginx从搭建到配置支持HTTPS的方法
安装
基础包
ububtuapt-get install build-essentialapt-get install libtoolcentosyum -y install gcc automake autoconf libtool makeyum install gcc gcc-c++
进入安装目录
cd /usr/local/src
安装 PCRE 支持正则表达 使 Nginx 支持 Rewrite 功能
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gztar -zxvf pcre-8.42.tar.gzcd pcre-8.42./configuremakemake install
安装 zlib 支持数据压缩
wget http://zlib.net/zlib-1.2.11.tar.gztar -zxvf zlib-1.2.11.tar.gzcd zlib-1.2.11./configuremakemake install
安装 openssl 支持 https
wget https://www.openssl.org/source/openssl-1.1.1-pre7.tar.gztar -zxvf openssl-1.1.1-pre7.tar.gzcd openssl-1.1.1-pre7./configuremakemake install
Nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gztar -zxvf nginx-1.14.0.tar.gzcd nginx-1.14.0./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_modulemakemake install
配置
配置文件地址
/usr/local/nginx/conf/nginx.conf
使用
命令
/usr/local/nginx/sbin/nginx # 启动 Nginx/usr/local/nginx/sbin/nginx -t # 检查 Nginx 配置文件正确性/usr/local/nginx/sbin/nginx -s reload # 重新载入配置文件/usr/local/nginx/sbin/nginx -s reopen # 重启 Nginx/usr/local/nginx/sbin/nginx -s stop # 停止 Nginx
进程关闭
# 查看进程号ps -ef|grep nginx# 正常退出kill -QUIT 进程号# 快速停止kill -TERM 进程号kill -INT 进程号# 强制退出kill -KILL nginx生成 cer 证书支持 https生成 cer 证书# 进入存放证书的目录/usr/local/nginx/conf/ssl# 创建服务器证书密钥文件 server.key 私钥openssl genrsa -des3 -out server.key 1024# 输入密码,确认密码,后面会使用# 创建签名请求的证书(CSR)openssl req -new -key server.key -out server.csr# 输出内容为:# Enter pass phrase for root.key: ← 输入前面创建的密码 # Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN# State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音# Locality Name (eg, city) []:BeiJing ← 市的全名,拼音# Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名# Organizational Unit Name (eg, section) []: ← 可以不输入# Common Name (eg, YOUR name) []: ← 此时不输入# Email Address []:admin@mycompany.com ← 电子邮箱,可随意填# Please enter the following 'extra' attributes# to be sent with your certificate request# A challenge password []: ← 可以不输入# An optional company name []: ← 可以不输入# 备份服务器密钥文件cp server.key server.key.org# 去除文件口令,生成公钥openssl rsa -in server.key.org -out server.key# Enter pass phrase for server.key.org: ← 输入前面创建的密码# 生成证书文件 server.crtopenssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
配置 https
# /usr/local/nginx/conf/nginx.conf## HTTPS server configuration#server { listen 443 ssl; # ssl 端口 server_name www.xingkongbj.com xingkongbj.com; # 域名 ssl on; # 开启 ssl ssl_certificate ssl/server.crt; ssl_certificate_key ssl/server.key; ssl_session_timeout 5m;# ssl_protocols SSLv2 SSLv3 TLSv1;# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;# ssl_prefer_server_ciphers on; location / { proxy_redirect off; # 禁止跳转 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://98.142.138.177/; }}# nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf# 原因是nginx缺少http_ssl_module模块,编译安装时带上--with-http_ssl_module配置就可以了# 切换到nginx源码包cd cd /usr/local/src/nginx-1.14.0/# 查看 ngixn 原有的模块/usr/local/nginx/sbin/nginx -V# 重新配置./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module# 重新编译,不需要 make install 安装。否则会覆盖make# 备份原有已经安装好的 nginxcp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bakcp /usr/local/nginx/conf/nginx.conf /usr/local/nginx.conf# 将刚刚编译好的 nginx 覆盖掉原来的 nginx(ngixn必须停止)cp ./objs/nginx /usr/local/nginx/sbin/ # 这时,会提示是否覆盖,请输入yes,直接回车默认不覆盖# 启动 nginx,查看 nginx 模块,发现已经添加/usr/local/nginx/sbin/nginx -V/usr/local/nginx/sbin/nginx -t/usr/local/nginx/sbin/nginx
总结
以上所述是小编给大家介绍的Nginx从搭建到配置支持HTTPS的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
输入
配置
支持
文件
证书
进程
密码
生成
模块
编译
全名
备份
密钥
拼音
服务器
目录
服务
方法
代号
公司
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
国三网络技术大题讲解
python通用数据库
购买存储服务器的合同无效吗
数据库常见考研复试题
成都海华瑞软件开发有限公司
网络安全门锁怎么样
公司员工数据库需要
电脑2k20服务器连不上怎么办
数据库中不能建立参照完整性
岳阳正规软件开发服务
腾讯视频无法连接服务器怎么办
大华视频综合管理服务器启动
百亿网络技术公司
服务器需要多少版本
服务器哪种软件好用
冷备用和热备数据库
数据库之间表插入数据
游戏服务器框架 开源
数据库的最新发展及应用
客天下网络技术有限公司
动力服务器
房山网络安全等级保护认证
太原触摸签名软件开发公司
网络安全标准化作用
融合服务器可以防火墙吗
授权访问 数据库
亳州咖啡点餐软件开发外包公司
厦门电脑软件开发培训机构
国家网络安全宣传周视频征集
php 操作数据库的函数