跟小编一起学:Nginx配置HTTPS服务器过程详情

服务器
跟小编一起学:nginx配置HTTPS服务器过程详情,希望对大家有所帮助。

nginx配置HTTPS服务器

一、 ubuntu配置nginx v1.4.6 HTTPS服务器

1.首先确保机器上安装了openssl和openssl-devel

pip install openssl  
pip install openssl-devel 
  • 1.
  • 2.

2.创建服务器私钥,命令会让你输入一个口令:

openssl genrsa -des3 -out server.key 1024 // 生成私钥 
  • 1.

第一步生成server.key密码:123456

3.创建签名请求的证书(CSR):

> openssl req -new -key server.key -out server.csr 
> 1 Country Name (2 letter code) [AU]:CN ←输入国家代码  
> 2 State or Province Name (full name) [Some-State]:SHANGHAI← 输入省名  
> 3 Locality Name (eg, city) []:SHANGHAI ←输入城市名  
> 4 Organization Name (eg, company) [Internet Widgits Pty Ltd]:11 ← 输入公司名  
> 5 Organizational Unit Name (eg, section) []:11 ← 输入组织单位名  
> 6 Common Name (eg, YOUR name) []:111.11.11.1 ← 输入主机名  
> 7 Email Address []:xxx@gmail.com ←输入电子邮箱地址 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

[[249095]]

4.在加载SSL支持的Nginx并使用上述私钥:

openssl rsa -in server.key -out server_nopwd.key 
  • 1.

5.配置nginx最后标记证书使用上述私钥和CSR:

openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt 
  • 1.

6.修改Nginx配置文件,让其包含新标记的证书和私钥:

http { 
include server/*.cn; 

  • 1.
  • 2.
  • 3.

7.修改Nginx配置文件,让其包含新标记的证书和私钥:

server { 
listen 443; 
server_name xx.online www.xx.online; 
ssl on
ssl_certificate /hk/keys/server.crt; 
ssl_certificate_key /hk/keys/server_nopwd.key
ssl_session_timeout 5m; 
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; 
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"
ssl_prefer_server_ciphers on
charset utf-8; 
location /media { 
alias /11/resource/project/media; 

location /static { 
alias /11/project/static

location / { 
uwsgi_pass 127.0.0.1:9011; 
include /11/project/uwsgi_params; 


  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

8.启动nginx服务器.

如果出现“[emerg] 10464#0: unknown directive “ssl” in /usr/local/nginx-0.6.32/conf/nginx.conf:74”则说明没有将ssl模块编译进nginx,在configure的时候加上“–with-http_ssl_module”即可

[root@localhost nginx-1.4.4]# ./configure –prefix=/usr/local/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module 
service nginx reload  
service nginx restart 
  • 1.
  • 2.
  • 3.

9.测试网站是否能够通过https访问

https://xx.online/admin

10.同时支持80和443同时访问配置:

server { 
listen 80 default backlog=2048; 
listen 443 ssl; 

  • 1.
  • 2.
  • 3.
  • 4.

 

责任编辑:武晓燕 来源: 今日头条
相关推荐

2019-07-22 09:13:50

Nginx算法浏览器

2021-07-28 23:32:09

Nginx服务器Https

2020-12-01 09:40:15

Harmony

2021-06-02 07:43:42

服务器阿里云配置

2020-12-03 11:34:12

Ability vs

2022-11-29 16:35:02

Tetris鸿蒙

2022-12-02 14:20:09

Tetris鸿蒙

2023-03-30 09:32:27

2022-11-14 17:01:34

游戏开发画布功能

2010-05-21 17:32:07

IIS服务器

2023-02-28 07:28:50

Spritepixijs

2023-11-13 22:27:53

Mapping数据库

2024-02-28 12:12:20

Pipeline数据机制

2023-04-26 07:42:16

WebGL图元的类型

2023-05-04 08:48:42

WebGL复合矩阵

2023-06-26 15:14:19

WebGL纹理对象学习

2023-11-30 15:23:07

聚合查询数据分析

2023-04-12 07:46:24

JavaScriptWebGL

2023-11-13 12:48:32

语言DSL

2023-03-29 07:31:09

WebGL坐标系
点赞
收藏

51CTO技术栈公众号