最近在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. JUC源码学习笔记8——ConcurrentHashMap源码分析1 如何实现低粒度锁的插入,如何实现统计元素个数,如何实现并发扩容迁移

    源码基于jdk1.8 这一片主要讲述ConcurrentHashMap如何实现低粒度锁的插入,如何实现统计元素个数,如何实现并发扩容迁移 系列文章目录和关于我 一丶ConcurrentHashMap概 ...

  2. Salesforce LWC学习(三十三) lightning-datatable 翻页bug处理

    本来lightning-datatable这种标签,基本上任何的项目都会用到而且很精通,所以当时感觉没有太大的单独一篇写的必要,在Salesforce LWC学习(三十) lwc superbadge ...

  3. SpringBoot 整合 Kafka 与 Avro 【No group.id】 问题解决方法

    [问题描述]:ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalK ...

  4. 这几个SQL语法的坑,你踩过吗

    本文已经收录到Github仓库,该仓库包含计算机基础.Java基础.多线程.JVM.数据库.Redis.Spring.Mybatis.SpringMVC.SpringBoot.分布式.微服务.设计模式 ...

  5. [ACM]queue队列模板

    思路 队列的原理基本与站队一样,队首出,队尾入,变化以后也是大同小异,写起来主要就是注意struct的相关知识,以及伪指针(分别指向队首和队尾+1),队尾序号要+1以防首位变量数字重合造成不必要的麻烦 ...

  6. GaussDB(DWS)网络调度与隔离管控能力

    摘要:调度算法是调度器的核心,设计调度算法要充分考虑业务场景和用户需求,没有万能的调度算法,只有合适的调度算法. 本文分享自华为云社区<GaussDB(DWS)网络调度与隔离管控能力>,作 ...

  7. yaml-cpp YAML格式处理库的介绍和使用(面向业务编程-文件格式处理)

    yaml-cpp YAML格式处理库的介绍和使用(面向业务编程-文件格式处理) YAML格式介绍 YAML的格式介绍,有关ini.json和xml或许很多人已经很了解了,但是关于YAML,还有许多人不 ...

  8. python-爬虫-css提取-写入csv-爬取猫眼电影榜单

    猫眼有一个电影榜单top100,我们将他的榜单电影数据(电影名.主演.上映时间.豆瓣评分)抓下来保存到本地的excle中 本案例使用css方式提取页面数据,所以会用到以下库 import time i ...

  9. [软件体系结构/架构]零拷贝技术(Zero-copy)[转发]

    0 前言 近期遇到难题:1个大数据集的查询导出API,因从数据库查询后占用内存极大,每次调用将消耗近100MB的JVM内存资源.故现需考虑研究和应用零拷贝技术. 如下全文摘自: 看一遍就理解:零拷贝原 ...

  10. DG:windows密码文件

    问题描述:搭建DG,找不到密码文件的位置,就给备库重新生成了一个密码文件,传到了备库,但是拉到了备库以后,恢复过程中,trace日志在报错,后来才知道windows下的密码文件跟linux平台下的面文 ...