# ============================================ # 彩虹易支付 Nginx 配置 # ============================================ upstream php-upstream { server php:9000; } server { listen 80; server_name _; root /var/www/html; index index.php index.html; charset utf-8; client_max_body_size 50m; # 反代环境下使用相对跳转,避免 301 到 http:// absolute_redirect off; # ========================================== # 信任宝塔 Nginx 反向代理传递的真实 IP # ========================================== set_real_ip_from 127.0.0.1; set_real_ip_from 172.16.0.0/12; set_real_ip_from 192.168.0.0/16; real_ip_header X-Forwarded-For; real_ip_recursive on; # ========================================== # 安全响应头 # ========================================== add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always; # ========================================== # 安全规则:禁止直接访问核心目录 # ========================================== location ^~ /includes { deny all; return 403; } location ^~ /plugins { deny all; return 403; } # install/index.php 在 install.lock 存在时自行拒绝重装;安装 SQL/锁文件不可下载。 location ~* ^/install/.*\.(sql|lock)$ { deny all; return 403; } # 保护敏感文件 location ~* /(config\.php|\.htaccess|\.git) { deny all; return 403; } # ========================================== # URL 重写规则(对应 nginx.txt) # ========================================== location / { # *.html → index.php?mod=xxx if (!-e $request_filename) { rewrite ^/(.[a-zA-Z0-9\-\_]+).html$ /index.php?mod=$1 last; } # /pay/xxx → pay.php?s=xxx rewrite ^/pay/(.*)$ /pay.php?s=$1 last; # /api/xxx → api.php?s=xxx rewrite ^/api/(.*)$ /api.php?s=$1 last; # /doc/xxx.html → index.php?doc=xxx rewrite ^/doc/(.[a-zA-Z0-9\-\_]+).html$ /index.php?doc=$1 last; try_files $uri $uri/ /index.php?$query_string; } # ========================================== # PHP 处理 # ========================================== location ~ \.php$ { fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; # 安全:防止上传文件被执行 fastcgi_param PHP_VALUE "open_basedir=/var/www/html:/tmp/:/var/lib/php/sessions/"; } # ========================================== # 静态资源缓存 # ========================================== # 前端补丁文件(后台布局 CSS/JS):始终回源校验,改版立即生效 location = /assets/dist/epay-ui.css { add_header X-Content-Type-Options "nosniff" always; add_header Cache-Control "no-cache" always; } location = /assets/dist/epay-ui.js { add_header X-Content-Type-Options "nosniff" always; add_header Cache-Control "no-cache" always; } location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ { expires 30d; add_header Cache-Control "public, immutable"; } # ========================================== # 上传目录:禁止执行 PHP # ========================================== location /assets/uploads/ { location ~* \.php$ { deny all; return 403; } } # ========================================== # 日志 # ========================================== access_log /var/log/nginx/epay-access.log; error_log /var/log/nginx/epay-error.log; }