linux安装nginx,设置https访问
-
首先安装依赖包
[root@centOS-2 ~]# yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel
-
使用wget下载nginx
[root@centOS-2 ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz
-
解包
[root@centOS-2 ~]# tar -zxvf nginx-1.20.2.tar.gz
-
将解好的包移动到/usr/local/目录下
[root@centOS-2 ~]# mv nginx-1.20.2 /usr/local/
-
安装nginx
[root@centOS-2 ~]# cd /usr/local/nginx-1.20.2/ [root@centOS-2 nginx-1.20.2]# ./configure --prefix=/usr/local/nginx-1.20.2/
-
编译
[root@centOS-2 ~]# make [root@centOS-2 ~]# make install
-
运行nginx
[root@centOS-2 sbin]# ./nginx
-
使用命令生成证书
# 新建目录crt cd /usr/local/nginx/conf/ mkdir crt cd crt # 生成key 输入密码后记住!!! openssl genrsa -des3 -out server.key 1024 # 生成证书 openssl req -new -key server.key -out server.csr #备份key cp server.key server.key.org openssl rsa -in server.key.org -out server.key openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
-
修改配置文件
server { listen 443 ssl; server_name localhost; ssl_certificate /usr/local/nginx/conf/crt/server.crt; ssl_certificate_key /usr/local/nginx/conf/crt/server.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; }
-
重启nginx服务
[root@centOS-2 sbin]# yum -y install psmisc [root@centOS-2 sbin]# killall nginx
-
成功使用https访问