LNMP——nginx负载均衡/nginx配置ssl

11月29日

12.17 Nginx负载均衡

Nginx负载均衡

· vim /uer/local/nginx/conf/vhost/load.conf 写入如下内容

upstream qq_com  名字

{

   ip_hash;  目的让同一个用户始终保持在一个机器上

   server 61.135.157.156:80;

   server 125.39.240.113:80;

}

server

{

   listen 80;

   server_name www.qq.com;

   location/

   {

      proxy_pass    http://qq_com;

      proxy_set_header Host $host;

      proxy_set_header X_Real_IP   $remote_addr;

      peoxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;

}

}

· upstream来指定多个web server

yum install -y bind-utils

dig qq.ocm  查看qq的ip(域名解析)

/usr/local/nginx/sbin/nginx -t

/usr/loacal/nginx/sbin/nginx -s reload   检查脚本并重新加载

curl -x127.0.0.1:80 www.qq.com

Nginx不支持代理https

12.18 ssl原理

8a63c92b17222e3fc2a7babbef92d80ddd2.jpg

12.19 生成ssl密钥对

生成ssl密钥对

· cd /usr/local/nginx/conf

rpm -qf ‘which openssl’ 查看命令用哪个包安装

· openssl genrsa -des3 -out tmp.key 2048  key文件为私钥。需要输入密码

· openssl rsa -in tmp.key -out aminglinux.key 转换key,取消密码 -in指定密钥 -out指定输入

· rm -f tmp.key

· openssl req -new -key aminglinux.key -out aminglinux.csr 生成证书请求文件,需要拿这个文件和私钥一起生成公钥文件

· openssl x509 -req -days 365 -in aminglinux.csr -singkey aminglinux.key -out aminglinux.crt   -days证书日期

· 这里的aminglinux.crt为公钥

12.20 Nginx配置ssl

Nginx 配置ssl

· vim /usr/local/nginx/conf/vhost/ssl.conf 加入如下内容

server 

{

  listen 443;

  server_name aming.com;

  index index.html index.php;

  root /data/wwwroot/aming.com;

  ssl on;  开启ssl

  ssl_certificate aminglinux.crt; 指定公钥

  ssl_certificate_key aminglinux.key; 指定私钥

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 指定协议

}

·/usr/local/nginx/sbin/nginx -t && -s reload 若报错unknown directive “ssl”,需要重新编译nginx,加上--with-http_ssl_module

  cd /usr/local/src/nginx-1.12.1/

· ./configure --prefix=/usr/local/nginx --with-http_ssl_module  

  make install

· mkdir /data/wwwroot/aming.com

/usr/local/nginx/sbin/nginx -t && -s reload 检查并重新加载

· echo “ssl test page.” >/data/wwwroot/aming.com/index.html

· vi /etc/hosts     编辑hosts, 增加127.0.0.1 aming.com

· curl https://aming.com/ 

 

转载于:https://my.oschina.net/u/3959687/blog/2963383

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LNMP 环境(Linux + Nginx + MySQL + PHP)中配置 SSL 证书,你可以按照以下步骤进行操作: 1. 获取 SSL 证书:你可以购买 SSL 证书或使用免费的工具(如 Let's Encrypt)来获取证书。确保你获得了证书文件(通常是以 `.crt` 结尾)和私钥文件(通常是以 `.key` 结尾)。 2. 将证书和私钥文件放置在服务器上:将证书和私钥文件上传到服务器上的安全目录中,例如 `/etc/nginx/ssl/`。 3. 配置 Nginx:找到 Nginx 的虚拟主机配置文件(通常位于 `/etc/nginx/conf.d/your_site.conf`),并进行以下修改: ``` server { listen 443 ssl; server_name your_domain.com; ssl_certificate /etc/nginx/ssl/your_certificate.crt; ssl_certificate_key /etc/nginx/ssl/your_private_key.key; # 可选:为了增加安全性,你可以配置其他 SSL 相关的设置,例如: # ssl_protocols, ssl_ciphers, ssl_prefer_server_ciphers, ssl_session_cache 等 location / { root /path/to/your/web/files; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/var/run/php/php<version>-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` 将 `your_domain.com` 替换为你的域名,将 `/etc/nginx/ssl/your_certificate.crt` 和 `/etc/nginx/ssl/your_private_key.key` 替换为你实际的证书和私钥文件的路径。将 `/path/to/your/web/files` 替换为你网站文件的实际路径。将 `<version>` 替换为你安装的 PHP 版本号。 4. 重启 Nginx:保存并关闭配置文件后,使用以下命令重启 Nginx 以使配置生效: ``` sudo systemctl restart nginx ``` 完成以上步骤后,你的 LNMP 环境将通过 HTTPS 提供安全连接,并且能够处理 PHP 文件。请确保在防火墙中打开了 443 端口,并在 DNS 中正确地将域名指向你的服务器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值