nginx安装参考:https://www.cnblogs.com/taiyonghai/p/6728707.html

自签证书生成参考:https://gmd20.github.io/blog/openssl%E7%94%9F%E6%88%90RSA%E5%92%8C%E6%A4%AD%E5%9C%86%E6%9B%B2%E7%BA%BF%E5%8A%A0%E5%AF%86%E5%85%AC%E9%92%A5%E5%AF%86%E9%92%A5%E5%88%9B%E5%BB%BA%E6%A0%B9CA%E7%AD%BE%E5%90%8DHTTPS%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%AF%81%E4%B9%A6%E7%AD%BE%E5%90%8D/

一:Nginx 安装

openssl安装

[root@localhost src]# tar zxvf openssl-fips-2.0.10.tar.gz
省略安装内容...

[root@localhost src]# cd openssl-fips-2.0.10

[root@localhost openssl-fips-2.0.10]# ./config && make && make install
省略安装内容...

pcre安装

[root@localhost src]# tar zxvf pcre-8.40.tar.gz
省略安装内容...

[root@localhost src]# cd pcre-8.40

[root@localhost pcre-8.40]# ./configure && make && make install
省略安装内容...

zlib安装

[root@localhost src]# tar zxvf zlib-1.2.11.tar.gz
省略安装内容...

[root@localhost src]# cd zlib-1.2.11

[root@localhost zlib-1.2.11]# ./configure && make && make install
省略安装内容...

SSL模块安装

[root@localhost src]# yum install openssl-devel
省略安装内容...

nginx安装

[root@localhost src]# tar zxvf nginx-1.10.2.tar.gz
省略安装内容...

[root@localhost src]# cd nginx-1.10.2

[root@localhost nginx-1.10.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module && make && make install
省略安装内容...

 

 

二、证书和私钥的生成

注意:将生成的服务器证书和私钥, 拷贝到/usr/local/nginx/conf/目录下, 测试可以使用自签证书。使用openssl自签即可。

建议使用ECC加密证书

[root@localhost conf]# ls -al
total 84
drwxr-xr-x.  3 root root 4096 Apr  5 15:29 .
drwxr-xr-x. 11 root root  151 Apr  5 13:34 ..
省略
-rw-r--r--.  1 root root  615 Apr  5 15:29 server.crt
-rw-r--r--.  1 root root  302 Apr  5 15:29 server.key
省略

三、配置文件

1.下面为配置文件 /usr/local/nginx/conf/nginx.conf  , 将HTTPS部分的server配置注释去掉,并设置正确的证书证书和私钥

[root@localhost conf]# cat nginx.conf

#user  nobody;

worker_processes  1;

#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 {

include       mime.types;

default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

#                  '$status $body_bytes_sent "$http_referer" '

#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;

#tcp_nopush     on;

#keepalive_timeout  0;

keepalive_timeout  65;

#gzip  on;

server {

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html;

index  index.html index.htm;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#    proxy_pass   http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

#    root           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

server {

listen       8000;

#    listen       somename:8080;

#    server_name  somename  alias  another.alias;

location / {

root   html;

index  index.html index.htm;

}

}

# HTTPS server

#

server {

listen       443 ssl;

server_name  localhost;

ssl_certificate      server.crt;

ssl_certificate_key  server.key;

ssl_session_cache    shared:SSL:1m;

ssl_session_timeout  5m;

ssl_ciphers  HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers  on;

location / {

root   html;

index  index.html index.htm;

}

}

}

四、开启nginx 服务器

 

开启nginx服务器 和查看服务器状态

[root@localhost conf]# /usr/local/nginx/sbin/nginx

[root@localhost conf]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

关闭nginx 服务器

[root@localhost conf]# ps -aux | grep nginx

root     11821  0.0  0.0  46936  1168 ?        Ss   15:29   0:00 nginx: master process ./nginx

nobody   11822  0.0  0.0  49552  3552 ?        S    15:29   0:00 nginx: worker process

root     12229  0.0  0.0 112712   972 pts/0    S+   17:19   0:00 grep --color=auto nginx

[root@localhost conf]# kill 11821

[root@localhost conf]# ps -aux | grep nginx

root     12231  0.0  0.0 112712   968 pts/0    S+   17:19   0:00 grep --color=auto nginx

五、关闭CentOS防火墙

 

关闭CentOS防火墙

 

[root@localhost conf]#

[root@localhost conf]# systemctl stop firewalld

[root@localhost conf]#

[root@localhost conf]# systemctl disable  firewalld

Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

六:客户端测试访问

大功告成:

CentOS使用nginx部署https服务的更多相关文章

  1. CentOS Mono Nginx 部署 MVC4+WebApi

    CentOS Mono Nginx 部署 MVC4+WebApi 经过几天的折磨,终于在CentOS上成功部署了MVC4+WebApi.Mono上的服务器推荐两种:Jexus(国产高人写的一款很牛的服 ...

  2. Nginx 部署HTTPS

    Nginx 部署HTTPS 系统:Linux Centos 7.4 x64 软件:Nginx 1.12.2 注:需要阿里云申请本地域名与证书并添加下载到本地. 注:证书文件为 xxxx.pem 与 x ...

  3. 【HTTPS】自签CA证书 && nginx配置https服务

    首先,搭建https服务肯定需要一个https证书.这个证书可以看做是一个应用层面的证书.之所以这么说是因为https证书是基于CA证书生成的.对于正式的网站,CA证书需要到有资质的第三方证书颁发机构 ...

  4. Nginx 配置https 服务

    一.HTTPS 服务 为什么需要HTTPS? 原因:HTTP不安全 1.传输数据被中间人盗用.信息泄露 2.数据内容劫持.篡改 HTTPS协议的实现 对传输内容进行加密以及身份验证 HTTPS加密校验 ...

  5. centos7.x下环境搭建(五)—nginx搭建https服务

    https证书获取 十大免费SSL证书 https://blog.csdn.net/ithomer/article/details/78075006 如果我们用的是阿里云或腾讯云,他们都提供了免费版的 ...

  6. 基于Nginx的https服务

    1.HTTPS协议的实现 1.为什么需要HTTPS? 原因:HTTP不安全 1.传输数据被中间人盗用.信息泄露 2.数据内容劫持.篡改 对传输内容进行加密以及身份验证 2.对称加密 非对称加密 3.H ...

  7. centos配置apache的https服务

    因为公司要开发微信小程序,由于小程序比较特殊,需要https服务,所以就研究了下apache的https服务了,大致过程如下: 1.向证书机构申请https证书,会得到证书和私钥 2.安装apache ...

  8. [CentOS] 结合Nginx部署DotNetCore的demo项目【转载】

    部署前准备 1.VisualStudio2017+.netcore2.0SDK 2.Centos7.2 3.SecureCRT,Xftp(根据自己喜好) 创建WebApi项目 修改Program.cs ...

  9. CentOS 7 Nginx部署.NET Core Web应用

    部署.NET Core运行时 必要前提 在安装.NET Core前,需要注册Microsoft签名秘钥并添加Microsoft产品提要,每台机器只需要注册一次,执行如下命令: sudo rpm -Uv ...

随机推荐

  1. js中substr、substring、slice的区别

    substr(start, length) substring(from, to) slice(from, to) 以上函数只传一个参数时,认为是起始位置,然后按照正方向截取 substring的参数 ...

  2. STM32L071CBTX操作ECC508

    因为我是在stm32上面做的加密操作,所以我只对stm32的方案做总结. 1.ATECC508的底层接口是i2c的,工程中跟i2c相关的操作放在文件hal_stm32l0_ateccx08_i2c.c ...

  3. [Ynoi2019模拟赛]Yuno loves sqrt technology III

    题目大意: 给你一个长为n的序列a,m次询问,每次查询一个区间的众数的出现次数,强制在线. 解题思路: 出题人题解 众所周知lxl是个毒瘤,Ynoi道道都是神仙题 首先得离散化. 分块后,预处理Fi, ...

  4. mysql的基础用法,水一下

    #和上一篇是一起的,上一篇就是为这个做insert <blockquote>/*思考题*/ create database spj; use spj;create table s( sno ...

  5. S50 抓取pattern数据

    S50(原V50) 测试机台湾久元电子研发的一款数字芯片测试系统,行业内有很多人使用: 现在记录下S50抓取pattern数据的一些方法: 程序主要是通过read_log配合c代码实现,pattern ...

  6. LeetCode——688. Knight Probability in Chessboard

    一.题目链接:https://leetcode.com/problems/knight-probability-in-chessboard/ 二.题目大意: 给定一个N*N的棋盘和一个初始坐标值(r, ...

  7. truffle init 从零开始创建简单DApp项目

    下面的部分软件需要FQ.这里默认你已经会***,不懂的可以自己搜索解决. 软件安装 chrome浏览器 下载地址 metamask插件 在谷歌应用商店中搜索metamask ganche(图形版) 下 ...

  8. 在Ubuntu下编译Qt错误及处理办法

    平台:Ubuntu16.04  64bit 虚拟机:VirtualBOX 编译软件:Qt 32bit (在64位环境下编译32bit的程序会出现很多错误,从编译器的安装以及整个库的编译) 问题一:er ...

  9. phpstorm 如何设置识别vue文件

    非常简单,步骤如下: 第一步: 设置->plugins->browser repositories 搜索vue.js,然后安装一下vue.js插件,重启ide. 第二步: Editor - ...

  10. [security CRT] VB实现自动下载脚本

    #$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True ' This ...