nginx https 与http 同时共有配置示例
时间: 2023-10-03 10:04:14 浏览: 50
好的,以下是一个 nginx 同时支持 http 和 https 的配置示例:
```
server {
listen 80; # 监听 http 端口
listen [::]:80;
server_name example.com;
location / {
# http 的访问规则
proxy_pass http://backend_server;
}
}
server {
listen 443 ssl; # 监听 https 端口
listen [::]:443 ssl;
server_name example.com;
ssl_certificate /path/to/cert.pem; # 指定 SSL 证书
ssl_certificate_key /path/to/key.pem; # 指定 SSL 证书私钥
location / {
# https 的访问规则
proxy_pass http://backend_server;
}
}
```
需要注意的是,在将 SSL 证书与私钥指定给 nginx 后,还需要配置 HTTPS 的协议选项,例如 SSL/TLS 协议版本,密码套件等,才能够成功启用 HTTPS。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)