码尚云_西安云计算培训_云计算运维培训机构

标题: nginx配置补充 [打印本页]

作者: 云客    时间: 2020-10-28 05:05
标题: nginx配置补充
补充说明:

  1. server {
  2.     listen 443 ssl; # 监听HTTPS端口
  3.     server_name example.com www.example.com;

  4.     ssl_certificate /path/to/certificate.pem; # SSL证书文件路径
  5.     ssl_certificate_key /path/to/private.key; # 私钥文件路径

  6.     ssl_protocols TLSv1.2 TLSv1.3; # 支持的SSL/TLS协议版本
  7.     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256; # 密码套件
  8.     ssl_prefer_server_ciphers on; # 首选服务器密码套件

  9.     # 其他配置与HTTP服务器相同...
  10. }
复制代码

  1. upstream backend {
  2.     server backend1.example.com weight=5; # 第一个后端服务器,权重为5
  3.     server backend2.example.com; # 第二个后端服务器,权重为1(默认值)
  4.     server backend3.example.com; # 第三个后端服务器,权重为1(默认值)
  5. }

  6. server {
  7.     listen 80;
  8.     server_name example.com;

  9.     location / {
  10.         proxy_pass http://backend; # 反向代理到后端服务器组
  11.         proxy_set_header Host $host;
  12.         proxy_set_header X-Real-IP $remote_addr;
  13.     }
  14. }
复制代码

  1. http {
  2.     limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s; # 定义一个名为mylimit的速率限制区域,大小为10MB,每秒允许1个请求

  3.     server {
  4.         location /api {
  5.             limit_req zone=mylimit burst=5 nodelay; # 对/api路径应用速率限制,允许突发5个请求且不延迟处理
  6.             proxy_pass http://localhost:8000;
  7.             proxy_set_header Host $host;
  8.             proxy_set_header X-Real-IP $remote_addr;
  9.         }
  10.     }
  11. }
复制代码

  1. location /static {
  2.     valid_referers none blocked example.com *.example.com; # 允许的referer列表
  3.     if ($invalid_referer) { # 如果referer不在允许的列表中
  4.         return 403; # 返回403 Forbidden错误
  5.     }

  6.     alias /var/www/static;
  7.     expires 30d;
  8. }
复制代码


以上是Nginx的一些常见配置示例,实际使用中可能需要根据具体需求进行调整和优化。在修改配置后,记得使用nginx -t检查语法并重启Nginx以应用新的配置。







欢迎光临 码尚云_西安云计算培训_云计算运维培训机构 (http://www.mashangcloud.com/) Powered by Discuz! X3.4