首页 > 开发 > Nginx > 正文

Nginx从搭建到配置支持HTTPS的方法

2020-07-28 15:57:41
字体:
来源:转载
供稿:网友
这篇文章主要介绍了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
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表