分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

nginx 支持 https 访问的配置——完整配置文件

发布时间:2023-09-06 02:01责任编辑:赖小花关键词:配置nginxhttp

关于https的介绍网上很多了,就不啰嗦了。

配置支持https的访问需要nginx安装了ssl模块。其次是要准备ssl证书,nginx版的证书包含了crt文件和key文件,这个ssl证书一般是从认证服务提供商那里申请。假定nginx服务已经准备妥当,现在需要增加https访问的支持,只需要修改一下nginx的虚拟主机配置文件就可以了。

先看完整的配置文件内容吧,重要的几个地方有写注释。

# your.domain.name.conf# 这一块是监听 80 端口的访问请求,也就是http的访问# 可以根据需要来决定要不要监听 80 端口,不需要的话可以直接删除这块server { ???listen ???????80; ???listen ???????[::]:80; ???server_name ??your.domain.name; ???root ?????????/your/web/root/path; ???????# 把 http 访问重定向到 https ???rewrite ^(.*)$ ???????https://$host$1 permanent;}###server { ???# 监听来自 443 端口的访问请求,也就是https的访问 ???listen ??????443; ???listen ??????[::]:443; ???server_name ?your.domain.name; ???root ????????/your/web/root/path; ???### ???if (!-e $request_filename) { ???????rewrite ^(.*)$ /index.php$1 last; ???} ???access_log ??/your/web/log/path/your_domain_name.access.log main; ???error_log ???/your/web/log/path/your_domain_name.error.log info; ???# 启用 ssl 支持,然后载入 crt 和 key 文件 ???ssl on; ???ssl_certificate /your/cert/file/path/your_domain_name/1_your.domain.name_bundle.crt; ???ssl_certificate_key /your/cert/file/path/your_domain_name/2_your.domain.name.key; ???### ???include /etc/nginx/default.d/*.conf; ???location / { ???????index index.php index.html; ???} ???location ~ .*\.php(\/.*)*$ { ???????fastcgi_pass ??127.0.0.1:9000; ???????fastcgi_index ?index.php; ???????fastcgi_param ?SCRIPT_FILENAME ?$document_root$fastcgi_script_name; ???????include ???????fastcgi_params; ???} ???error_page 404 /404.html; ???location = /40x.html { ???} ???error_page 500 502 503 504 /50x.html; ???location = /50x.html { ???????}}

修改完成后记得重启一下nginx服务。

以上是nginx的虚拟主机配置文件,具体存放位置会有些不一样,我的是CentOS服务器,nginx配置文件存放在 /etc/nginx/conf.d/ 目录下(有些主机商提供部署好的web环境,路径也可能不一样)。

关于里面的配置内容,不必全盘搬照(你能看得出来,我这里服务器端用的是PHP语言),只要注意有注释的地方就可以了。

nginx 支持 https 访问的配置——完整配置文件

原文地址:https://www.cnblogs.com/alanabc/p/9214751.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved