nginx 绑定https
时间: 2023-09-21 12:12:33 浏览: 111
要在Nginx上绑定HTTPS,可以使用以下两种方法:
方法一是修改nginx.conf文件,在配置中添加以下内容:
```
server {
listen 80;
listen 443 ssl;
server_name api.cswendu.com;
index index.php index.html index.htm;
root /home/wwwroot/default;
ssl_certificate /usr/local/nginx/conf/https/api.cswendu.com_chain.crt;
ssl_certificate_key /usr/local/nginx/conf/https/api.cswendu.com_key.key;
# 省略其他操作
# ...
}
```
这个方法是直接在服务器配置中设置监听端口为80和443,并指定证书文件的路径和私钥文件的路径。
方法二是通过重定向或重写来实现绑定HTTPS。可以使用以下两种方式之一:
方式一是通过强制重定向将HTTP请求转发到HTTPS:
```
server {
listen 80;
server_name www.example.com;
return 301 https://$host$request_uri;
}
```
方式二是通过URL重写将HTTP的URL重写为HTTPS:
```
server {
listen 80;
server_name www.example.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
```
以上就是在Nginx上绑定HTTPS的方法,可以根据具体情况选择其中一种方式进行配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [nginx绑定https证书,保证http和https都能访问](https://blog.csdn.net/weixin_41827162/article/details/103494771)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Nginx配置https](https://blog.csdn.net/mocoll/article/details/129339093)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文