统一身份认证负载

特别说明:项目中的统一身份认证,与天音综合评价生产环境的配置差异不大!!!

  • 在宝塔Linux面板中创建 Nginx 负载
  • 拷贝生产环境的 Nginx 配置
  • 粘贴拷贝的 Nginx 配置到项目环境

在宝塔Linux面板中创建 Nginx 负载

*特别说明:这里以瓯海教育局,统一身份认证域名 zhpjrz.ohedu.cn 为例 *

  • 点击 PHP 项目,列表如下
  • 点击 添加站点,输入域名 zhpjrz.ohedu.cn 和 备注

拷贝生产环境的 Nginx 配置

特别说明:下面是天音综合评价SaaS - 统一身份认证域名 zhpjxtrz.91118.com 的负载配置

  • 务必遵守负载配置中的命名规范
server
{
    listen 80;
    listen 443 ssl http2 ;
    server_name zhpjxtrz.91118.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/zhpjxtrz.91118.com;
    #CERT-APPLY-CHECK--START
    # 用于SSL证书申请时的文件验证相关配置 -- 请勿删除
    include /www/server/panel/vhost/nginx/well-known/zhpjxtrz.91118.com.conf;
    #CERT-APPLY-CHECK--END

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    /www/server/panel/vhost/cert/zhpjxtrz.91118.com/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/zhpjxtrz.91118.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;

    #SSL-END

    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END

    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-00.conf;
    #PHP-INFO-END

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/zhpjxtrz.91118.com.conf;
    #REWRITE-END

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }

    #禁止在证书验证目录放入敏感文件
    if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
        return 403;
    }

    location / {
      proxy_pass http://zhpjxtrz_91118_com_cas;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header REMOTE-HOST $remote_addr;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_http_version 1.1;
      #Set Nginx Cache
      if ( $uri ~* "\.(gif|png|jpg|jpeg|css|js|woff|woff2)$" ) {
        expires 365d;
      }
      # 设置页面不缓存以 html、htm 结尾的文件
      if ($request_filename ~* .*\.(?:htm|html)$) {  
        add_header Cache-Control "no-store, no-cache, must-revalidate, private, proxy-revalidate, max-age=0";
        add_header Pragma no-cache;
        add_header Expires 0;
        expires off;
      }
    }

    access_log  /www/wwwlogs/zhpjxtrz.91118.com.log;
    error_log  /www/wwwlogs/zhpjxtrz.91118.com.error.log;
}

# 统一身份认证平台
upstream zhpjxtrz_91118_com_cas {
  server 192.168.3.221:31085 weight=1 max_fails=5 fail_timeout=60s;
  server 192.168.3.222:31085 weight=1 max_fails=5 fail_timeout=60s;
  server 192.168.3.223:31085 weight=1 max_fails=5 fail_timeout=60s;
  ip_hash;
  keepalive 256;
}

粘贴并改动 Nginx 配置到项目环境

特别说明:现在以瓯海教育局的项目环境为例,进行改动。

  • 负载配置中的命名规范,如:zhpjxtrz_91118_com 指 zhpjxtrz.91118.com
  • 这里以瓯海教育局,统一身份认证域名 zhpjrz.ohedu.cn 为例
    • 把 zhpjxtrz_91118_com 改为 zhpjrz_ohedu_cn
    • 把 zhpjxtrz.91118.com 改为 zhpjrz.ohedu.cn
  • 去除 Https 配置,修改真实的下游IP
server
{
    listen 80;
    server_name zhpjrz.ohedu.cn;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/zhpjrz.ohedu.cn;
    #CERT-APPLY-CHECK--START
    # 用于SSL证书申请时的文件验证相关配置 -- 请勿删除
    include /www/server/panel/vhost/nginx/well-known/zhpjrz.ohedu.cn.conf;
    #CERT-APPLY-CHECK--END

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END

    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END

    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-00.conf;
    #PHP-INFO-END

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/zhpjrz.ohedu.cn.conf;
    #REWRITE-END

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }

    #禁止在证书验证目录放入敏感文件
    if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
        return 403;
    }

    location / {
      proxy_pass http://zhpjrz_ohedu_cn_cas;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header REMOTE-HOST $remote_addr;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_http_version 1.1;
      #Set Nginx Cache
      if ( $uri ~* "\.(gif|png|jpg|jpeg|css|js|woff|woff2)$" ) {
        expires 365d;
      }
      # 设置页面不缓存以 html、htm 结尾的文件
      if ($request_filename ~* .*\.(?:htm|html)$) {
        add_header Cache-Control "no-store, no-cache, must-revalidate, private, proxy-revalidate, max-age=0";
        add_header Pragma no-cache;
        add_header Expires 0;
        expires off;
      }
    }

    access_log  /www/wwwlogs/zhpjrz.ohedu.cn.log;
    error_log  /www/wwwlogs/zhpjrz.ohedu.cn.error.log;
}

# 统一身份认证平台
upstream zhpjrz_ohedu_cn_cas {
  server 192.168.3.221:31085 weight=1 max_fails=5 fail_timeout=60s;
  server 192.168.3.222:31085 weight=1 max_fails=5 fail_timeout=60s;
  server 192.168.3.223:31085 weight=1 max_fails=5 fail_timeout=60s;
  ip_hash;
  keepalive 256;
}
作者:杭州天音  创建时间:2025-05-30 18:19
最后编辑:杭州天音  更新时间:2025-11-07 09:18