云溪的 blog
  • Archive
  • Media
  • Search
  • Tags
  • About
Home » Tags

WEB开发

Nginx、CGI、FastCGI、php-fpm关系

NGINX 和 PHP 是一对很好的搭档,那么 nginx 是如何与 php 结合实现 对外的网络访问呢? 首先 NGINX 作为一个 web 服务器只能处理静态请求,关于动态请求,是通过 CGI 具备的动态请求能力。 NGINX会将动态请求交给 CGI 处理,CGI 将处理结果返回给 NGINX,NGINX 再将请求的结果返给给浏览器 CGI 的作用 当在浏览器中输入一个动态地址时,如 /index.php, 通过 DNS 解析,最终请求会到 web 服务器上,当 NGINX 发现请求时动态请求。会交给 PHP 解释器处理此请求,那再给 NGINX 需要给 PHP 解释器传输哪些数据呢?请求地址,请求方法,请求参数这些东西总归是要有的,但是也不能仅仅是这些,像请求头和 cookie … 也应该包含其中。 那么怎么确定到底该传输哪些数据,以及以什么样的格式传输呢? CGI 就是解决这个问题而生的。 CGI 全程通用网关接口 (英语:Common Gateway Interface,CGI) 是为提供网络服务而执行控制台应用的程序,提供于服务器上实现动态网页的通用协议。通常情况下,一次请求对应一个CGI 脚本的执行,生成一个 HTML。 CGI 接口规定了 nginx 与动态解释器之前传输数据的参数和格式,为 nginx 和脚本解释器之间建立起了一个桥梁。 CGI 的存在使 web 服务器与动态语言之间的关系进行了解耦,使得 web 服务器可以处理的动态请求,但是 CGI 的设计使通过进程的方式来处理动态请求的,当动态请求过来后,CGI 会起一个进程进行处理,请求结束后关闭进程. ...

January 12, 2022 · 1 min · 云溪

申请 let's encrypt 通配符 ssl 证书

在<使用 let’s encrypt 为网站开启 https>一问中,讲述了,如何用 let’s encrypt 为网站开启 https 协议,这篇内容讲一下如何申请 let’s encrypt 通配符证书 什么是通配符证书 通配符 SSL 可以保护网站的 URL 及其所有子域(数量不限)。例如,一个单独的通配符证书就可以保护 www.artacode.com、blog.artacode.com 和 store.artacode.com。 通配符证书可以保护通用域名和您在提交申请时指定的级别下的所有子域。只需在通用域名左侧的子域区域添加星号 (*) 即可。 举例 如果为 *.artacode.com 申请证书,则可以保护: artacode.com www.artacode.com photos.artacode.com blog.artacode.com 如果为 *.www.artacode.com 申请证书,则可以保护: www.artacode.com mail.www.artacode.com photos.www.artacode.com blog.www.artacode.com 通配符证书可以像常规 SSL 证书一样为网站提供保护,并且申请是使用同一种验证方法进行处理的。不过,一些 Web 服务器可能要求使用通配符证书的每个子域都有唯一的 IP 地址。 如何申请 let’s encrypt 通配符证书 安装 Certbot $ wget https://dl.eff.org/certbot-auto $ sudo mv certbot-auto /usr/local/bin/certbot-auto $ sudo chown root /usr/local/bin/certbot-auto $ sudo chmod 0755 /usr/local/bin/certbot-auto 申请证书 certbot-auto --server https://acme-v02.api.letsencrypt.org/directory -d "*.artacode.com" -d "artacode.com" --manual --preferred-challenges dns-01 certonly //这里多加了一个 `-d "artacode.com"` 是因为 `-d "*.artacode.com"` 不包含 artacode.com 1. 填写接受通知的邮箱 Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): test@test.com 2. 同意协议 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: (A)gree/(C)ancel: a 3. 同意证书服务器记录本机IP - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that. Are you OK with your IP being logged? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4. 设置域名解析 Please deploy a DNS TXT record under the name _acme-challenge.artacode.cn with the following value: xxxxxxxxxxxxxx Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue 回车继续 5. 生成证书成功 Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/artacode.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/artacode.com/privkey.pem Your cert will expire on 2019-11-01. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le 配置 Nginx server { server_name xx.artacode.com; listen 443 http2 ssl; ssl_certificate /path/.acme.sh/domain/fullchain.cer; ssl_certificate_key /path/.acme.sh/domain/domain.key; ssl_trusted_certificate /path/.acme.sh/domain/ca.cer; } 总结 除了上述方法之外也有一些自动生成的脚本比如acme,就是在 github start 挺多的一个项目,除了手动申请之外也可以借助脚本快速申请 ssl 通配符证书. ...

August 3, 2019 · 3 min · 云溪

使用 let's encrypt 为网站开启 https

启用可用通道 $ yum -y install yum-utils $ yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional 安装 Certbot $ sudo yum install certbot python2-certbot-nginx 获取 nginx 服务器证书 $ sudo certbot certonly --nginx 遇到问题 certbot 未找到 nginx 二进制文件 The nginx plugin is not working; there may be problems with your existing configuration. The error was: NoInstallationError(“Could not find a usable ’nginx’ binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.”,) 由于我机器之前机器上已经安装 nginx 安装目录为 /usr/local/nginx/sbin/nginx 而 certbot 默认会到 /usr/bin/nginx 目录下找,因此需要建立一个软连接 ...

July 30, 2019 · 1 min · 云溪
« Prev 
© 2025 云溪的 blog