ZhiBing's blog(码上看世界) ZhiBing's blog(码上看世界)
首页
  • Linux工具链

    • shell命令
  • 构建

    • CMake
    • Makefile
  • 版本管理

    • Git
    • Github
  • IDE及工具

    • vscode
    • CLion
  • 设计模式

    • 设计原则
  • 编程语言

    • C++
    • Go
    • Python
    • Shell
  • 调试

    • gdb
  • 开发者测试

    • gtest
  • 系统支撑

    • 操作系统
  • 性能优化

    • 编译优化选项
    • perf
    • valgrind
  • 容器

    • Docker
  • 微服务

    • Rancher
  • 其他
  • 随笔
  • 友情链接
收藏
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)

ZhiBing Zheng

时间会回答成长
首页
  • Linux工具链

    • shell命令
  • 构建

    • CMake
    • Makefile
  • 版本管理

    • Git
    • Github
  • IDE及工具

    • vscode
    • CLion
  • 设计模式

    • 设计原则
  • 编程语言

    • C++
    • Go
    • Python
    • Shell
  • 调试

    • gdb
  • 开发者测试

    • gtest
  • 系统支撑

    • 操作系统
  • 性能优化

    • 编译优化选项
    • perf
    • valgrind
  • 容器

    • Docker
  • 微服务

    • Rancher
  • 其他
  • 随笔
  • 友情链接
收藏
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)
  • 其他

    • 安装 mariadb 数据库
    • 创建自己的jekyll主题
    • 搭建私有云盘
    • 搭建Git服务器
    • Linux开放端口
    • 内核链表
    • 树莓派4安装k3d
    • 树莓派4安装k3s
    • 树莓派4更换镜像源
    • 树莓派4设置静态IP
    • 树莓派安装docker
    • 远程连接mariadb数据库
    • Latex
    • mac安装jekyll
    • docker + nextcloud 搭建私有云(Linux)
    • nginx使用自签名SSL证书
      • 创建 SSL 证书
      • nginx 配置 SSL
    • raspbian-buster-lite安装桌面
    • ubuntu18.04 + jekyll 搭建个人博客站
    • Ubuntu刷新DNS缓存
    • wsl后台运行程序
    • xshell script api
    • HPE gen10 plus 安装telsa P4驱动
    • HPE gen10 plus 安装ESXI 7
    • ESXI 7安装黑群晖
    • ESXI 7安装win10
  • 随笔

  • 专题

  • 友情链接
  • 更多
  • 其他
zhengzhibing
2022-06-16
目录

nginx使用自签名SSL证书

# nginx 使用自签名 SSL 证书

# 创建 SSL 证书

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/your-selfsigned.key -out /etc/ssl/certs/your-selfsigned.crt
1

# nginx 配置 SSL

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bk
sudo vim /etc/nginx/sites-available/default
# 将请求重定向到https
# 启动https服务
1
2
3
4

完整的配置如下:

# 将your_ip和ssl密钥文件替换
server {
	listen 80 default_server;
	listen [::]:80 default_server;
	server_name your_ip;
	return 301 https://$server_name$request_uri;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www;

	# Add index.php to the list if you are using PHP
	index index.html index.htm index.nginx-debian.html;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	}

	# pass PHP scripts to FastCGI server
	#
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
	#
	#	# With php-fpm (or other unix sockets):
		fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
	#	# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	location ~ /\.ht {
		deny all;
	}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
	listen 443 ssl default_server;
	listen [::]:443 ssl default_server;

	root /var/www;
	index index.html index.htm index.nginx-debian.html;

	ssl_certificate /etc/ssl/certs/your-selfsigned.crt;
	ssl_certificate_key /etc/ssl/private/your-selfsigned.key;

	location / {
		try_files $uri $uri/ =404;
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

重启 nginx 服务

service nginx restart
1
#nginx
上次更新: 2022/06/17, 07:22:19
docker + nextcloud 搭建私有云(Linux)
raspbian-buster-lite安装桌面

← docker + nextcloud 搭建私有云(Linux) raspbian-buster-lite安装桌面→

最近更新
01
HPE gen10 plus 安装ESXI 7
06-12
02
ESXI 7安装黑群晖
06-12
03
ESXI 7安装win10
06-12
更多文章>
Theme by Vdoing | Copyright © 2022-2024 ZhBing Zheng | 粤ICP备2022062743号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式