最近在nginx中配置一个443端口

一、安装nginx

首先得先安装个nginx

1、安装依赖包

# 一键安装上面四个依赖
[root@dex ~]# yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2、下载并解压nginx安装包

# 创建一个文件夹
[root@dex ~]# cd /usr/local [root@dex local]# mkdir nginx [root@dex local]# cd nginx # 下载tar包
[root@dex nginx]# wget http://nginx.org/download/nginx-1.13.7.tar.gz # 解压 nginx 包
[root@dex nginx]# tar -xvf nginx-1.13.7.tar.gz

手动下载nginx http://nginx.org/en/download.html

3、执行安装nginx

#进入nginx目录
[root@dex nginx]# cd nginx-1.13.7 #执行编译命令
[root@dex nginx-1.13.7]# ./configure #执行make命令
[root@dex nginx-1.13.7]# make #执行make install命令
[root@dex nginx-1.13.7]# make install
4、配置nginx

# 打开配置文件
[root@dex ~]# vi /usr/local/nginx/conf/nginx.conf
5、启动nginx

[root@dex ~]#/usr/local/nginx/sbin/nginx
6、查看nginx进程

[root@dex nginx-1.13.7]# ps -ef|grep nginx
root 22988 1 0 Dec20 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 22989 22988 0 Dec20 ? 00:00:00 nginx: worker process
root 23638 23598 0 09:06 pts/0 00:00:00 grep --color=auto nginx
[root@dex nginx-1.13.7]#

二、下载ssl证书



然后解压下载的 证书zip



会得到三个文件,我们打开nginx 的文件夹

三、配置ssl

然后将这个两个文件上传到linux(我是上传到 /opt/sslCertificate/)目录下


[root@dex ~]# ll /opt/sslCertificate/
total 8
-rw-r--r-- 1 root root 3733 Dec 20 21:25 1_www.benpaodehenji.com_bundle.crt
-rw-r--r-- 1 root root 1704 Dec 20 21:25 2_www.benpaodehenji.com.key

ssl配置如下

    server {
listen 443 ssl;
server_name www.benpaodehenji.com; ssl_certificate /opt/sslCertificate/1_www.benpaodehenji.com_bundle.crt;
ssl_certificate_key /opt/sslCertificate/2_www.benpaodehenji.com.key; ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m; #ssl_ciphers HIGH:!aNULL:!MD5;
#ssl_prefer_server_ciphers on; location / {
root /opt/html;
index index.html index.htm;
}
location /vueapp/ {
proxy_pass http://127.0.0.1:8191/;
} }

然后监听80强制反向代理到https


server {
listen 80;
server_name www.benpaodehenji.com ;
#charset koi8-r;
#access_log logs/host.access.log main; rewrite ^(.*)$ https://${server_name}$1 permanent;
location / {
proxy_pass https://benpaodehenji.com;
}
}

配置完成后运行/usr/local/nginx/sbin/nginx -t 时提示 如下错误


[root@dex sbin]# ./nginx -t
nginx: [emerg] https protocol requires SSL support in /usr/local/nginx/conf/nginx.conf:50
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

这个是nginx 不支持 https,接下来得进入如下配置,让其支持ssl

四、配置nginx 支持ssl

1、首先cd /usr/local/nginx/nginx-1.13.7 然后执行如下命令

[root@dex nginx-1.13.7]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
checking for OS
+ Linux 3.10.0-957.21.3.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
.....省略
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

这里并可没有完,需要先停掉nginx 然后在执行make 进行重新编译

注意不要使用make install那样就是重新安装一次 nginx 了


[root@dex nginx-1.13.7]# make
make -f objs/Makefile
make[1]: Entering directory `/usr/local/nginx/nginx-1.13.7'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/nginx.o \
... 省略
-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/usr/local/nginx/nginx-1.13.7'
2、执行完成后,我们备份一下原来的nginx (这个以防万一,如果你的nginx中没有其他部署那倒是无所谓)

[root@dex nginx-1.13.7]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak
3、 再把刚才编译的nginx 拷贝覆盖原来的nginx

[root@dex nginx-1.13.7]# cp ./objs/nginx /usr/local/nginx/sbin/
4、nginx 安装情况

[root@dex nginx-1.13.7]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.13.7
5、 在执行一下nginx -t 检测一下

[root@dex nginx-1.13.7]# /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
6、启动nginx

[root@dex nginx-1.13.7]# /usr/local/nginx/sbin/nginx # 看看哈进程
[root@dex nginx-1.13.7]# ps -ef|grep nginx
root 22988 1 0 22:45 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 22989 22988 0 22:45 ? 00:00:00 nginx: worker process
root 23014 20315 0 22:51 pts/0 00:00:00 grep --color=auto nginx
[root@dex nginx-1.13.7]#

记录下其他nginx相关命令


./nginx 启动nginx
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。 ./nginx -s reload 重新加载配置

linux 进程查询、 关闭


[root@dex sbin]# ps -ef|grep nginx
nobody 6715 14665 0 Dec12 ? 00:00:00 nginx: worker process
root 14665 1 0 Nov03 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
root 22551 20315 0 22:06 pts/0 00:00:00 grep --color=auto nginx
[root@dex sbin]# kill -9 14665
[root@dex sbin]# kill -9 22551
-bash: kill: (22551) - No such process

nginx: [emerg] https protocol requires SSL support in /usr/local/nginx/conf/nginx.conf:50的更多相关文章

  1. nginx: [emerg] directive "location" has no opening "{" in /usr/local/nginx//conf/nginx.conf:75

    1.报错:[emerg]directive "location" has no opening "{" in ..... 解决方法: 由于对应行或者附近行的“{ ...

  2. 已安装nginx支持https配置 the "ssl" parameter requires ngx_http_ssl_module

    原文链接:https://blog.seosiwei.com/detail/28 nginx已安装,ssl模块未安装的解决方法: 如果需要在linux中编译自己的nginx服务器,请参照:https: ...

  3. nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx.conf:36

    nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx ...

  4. nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

    nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory) ...

  5. nginx: [error] invalid PID number “” in “/usr/local/var/run/nginx/nginx.pid”

    在Mac上用brew安装Nginx,然后修改Nginx配置文件,再重启时报出如下错误: nginx: [error] invalid PID number "" in " ...

  6. 【防坑指南】nginx重启后出现[error] open() “/usr/local/var/run/nginx/nginx.pid” failed

    重新启动nginx后,出现报错,原因就是下没有nginx文件夹或没有nginx.pid文件,为什么会没有呢? 原因就是每次重新启动,系统都会自动删除文件,所以解决方式就是更改pid文件存储的位置, 打 ...

  7. nginx启动或者重启失败,报错nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

    第一种方案: 1. 执行命令 :open /usr/local/etc/nginx 打开nginx安装目录 nginx安装目录默认位置有:(找到适合你的) /etc/nginx/nginx.conf, ...

  8. nginx停止后再启动出现: [error] open() "/usr/local/nginx/logs/nginx.pid" failed错误的解决方法

    为了备份数据 手动停止了服务器的nginx 结果启动时报错 nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" fail ...

  9. 【转】Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  10. Linux下nginx配置https协议访问

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

随机推荐

  1. 联邦学习开源框架FATE架构

    作者:京东科技 葛星宇 1.前言 本文除特殊说明外,所指的都是fate 1.9版本. fate资料存在着多处版本功能与发布的文档不匹配的情况,各个模块都有独立的文档,功能又有关联,坑比较多,首先要理清 ...

  2. 简述SpringAOP的实现原理

    ​ Spring默认采取的动态代理机制实现AOP,当动态代理不可用时 (代理类无接口)会使用CGlib机制. Spring提供了两种方式来生成代理对象:JDKProxy和Cglib,具体使用哪种方式生 ...

  3. 发布新版博客备份功能:生成 sqlite 数据库文件,vscode 插件可查看

    大家好,最近我们重新开发了园子的博客备份功能,今天发布第一个预览版,欢迎大家试用. 点击博客后台侧边栏的博客备份进入新版博客备份: 点击创建备份按钮创建博客备份任务(目前每天只能创建一次备份),待备份 ...

  4. NX二次开发:保存时导出PDF并打开

    该工程为在保存时执行开发的功能,函数入口点ufput.其他还有新建.打开.另存等都可以加入开发的操作,具体看UF_EXIT下的介绍. 用户出口是一个可选特性,允许你在NX中某些预定义的位置(或出口)自 ...

  5. Revit BIM模型在ArcGIS Pro中的数据组织及转换成SLPK后的图层结构解析

    ArcGIS Pro对Revit 数据有自己的一套分层方式. 在ArcGIS Pro中打开bim文件会发现都是按照相同的方式组织数据: 将rvt格式数据转换成SLPK格式后的数据结构(将slpk数据直 ...

  6. Java 8 中需要知道的4个函数式接口-Function、Consumer、Supplier、Predicate

    前言 Java 8 中提供了许多函数式接口,包括Function.Consumer.Supplier.Predicate 等等.这 4 个接口就是本篇将要分享的内容,它们都位于 java.util.f ...

  7. 回顾.NET系列:Framework、Net Core、Net 过往

    目录 一.个人最近工作变化 二.Framework.Net Core..NET 时过境迁 Framework:爱你定格在4.8 .Net Foundation:.Net变革大脑 重新统一的 .NET ...

  8. 从零开始学Vue(一)—— Vue.js 入门

    概述 vue.js作为现在笔记热门的JS框架,使用比较简单易上手,也成为很多公司首选的JS框架. 但是对于初学者可能学起来有些麻烦,所以推出<从零开始学Vue>系列博客,本系列计划推出19 ...

  9. 【Vue项目】尚品汇(四)Search组件开发

    Search模块开发 分析:1)编写静态页面 2)编写api 3)编写vuex三大件 4)组件获取仓库数据,并进行动态展示 1 SearchSelector 1 编写api export const ...

  10. API 接口主流协议有哪些?如何创建 HTTP/HTTP、WebSocket/WebSockets、TCP/UDP、gRPC、SOAP、Dubbo/HSF 等不同协议?

    API 接口协议繁多,不同的协议有着不同的使用场景.70% 互联网应用开发者日常仅会接触到最通用的 HTTP 协议,相信大家希望了解更多其他协议的信息.我们今天会给大家介绍各种 API 接口主流协议和 ...