不灭的焱

革命尚未成功,同志仍须努力 Trae下载

作者:AlbertWen  添加时间:2026-06-22 13:05:46  修改时间:2026-08-14 00:51:43  分类:04.运维体系  编辑

目录

下面给你一份 子路径为 /ticket,但 osTicket 物理目录不在主站目录下 的 Nginx 配置方案。

也就是这种部署方式:

访问地址:
https://your-domain.com/ticket/

主站目录:
/www/wwwroot/your-domain.com

osTicket 真实目录:
/www/wwwroot/osticket

或者:

主站目录:
/www/wwwroot/aiops.fuyo.com

osTicket 真实目录:
/data/www/osticket

这种情况 不能简单用 root,要用 alias

一、目录结构示例

假设你的主站是:

/www/wwwroot/your-domain.com

osTicket 实际放在:

/www/wwwroot/osticket

osTicket 目录结构大概是:

/www/wwwroot/osticket/
├── index.php
├── api/
├── scp/
├── include/
├── js/
├── css/
├── assets/
└── ...

访问路径是:

https://your-domain.com/ticket/

后台路径是:

https://your-domain.com/ticket/scp/

API 路径是:

https://your-domain.com/ticket/api/

二、完整 Nginx 配置方案

下面是完整 server 配置示例。

你需要把:

your-domain.com
/www/wwwroot/osticket
/tmp/php-cgi-83.sock

改成你的真实环境。

server {
    listen 80;
    server_name your-domain.com;

    root /www/wwwroot/your-domain.com;
    index index.php index.html index.htm;

    access_log /www/wwwlogs/your-domain.access.log;
    error_log  /www/wwwlogs/your-domain.error.log;

    client_max_body_size 50m;

    # /ticket 自动跳转到 /ticket/
    location = /ticket {
        return 301 /ticket/;
    }

    # osTicket 前台入口
    location /ticket/ {
        alias /www/wwwroot/osticket/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/index.php?$query_string;
    }

    # osTicket 后台入口
    location /ticket/scp/ {
        alias /www/wwwroot/osticket/scp/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/scp/index.php?$query_string;
    }

    # osTicket API 入口
    location /ticket/api/ {
        alias /www/wwwroot/osticket/api/;

        try_files $uri $uri/ /ticket/api/http.php?$query_string;
    }

    # 重点:支持 ajax.php/content/12/manage 这种 PATH_INFO 地址
    location ~ ^/ticket/(.+?\.php)(/.*)?$ {
        alias /www/wwwroot/osticket/$1;

        fastcgi_pass unix:/tmp/php-cgi-83.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME /www/wwwroot/osticket/$1;
        fastcgi_param SCRIPT_NAME /ticket/$1;
        fastcgi_param PATH_INFO $2;
        fastcgi_param PATH_TRANSLATED /www/wwwroot/osticket$2;
    }

    # 禁止访问 osTicket 配置文件
    location ~* ^/ticket/include/ost-config\.php$ {
        deny all;
    }

    # 安装完成后禁止访问 setup
    location ~* ^/ticket/setup/ {
        deny all;
    }

    # 禁止访问敏感目录
    location ~* ^/ticket/(sql|doc|scripts)/ {
        deny all;
    }

    # 禁止访问隐藏文件
    location ~ /\. {
        deny all;
    }

    # osTicket 静态资源缓存
    location ~* ^/ticket/.+\.(jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot)$ {
        alias /www/wwwroot/osticket/;
        expires 7d;
        access_log off;
    }
}

三、HTTPS 版本

如果你已经开启 SSL,用这个版本:

server {
    listen 80;
    server_name your-domain.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name your-domain.com;

    root /www/wwwroot/your-domain.com;
    index index.php index.html index.htm;

    ssl_certificate     /www/server/panel/vhost/cert/your-domain.com/fullchain.pem;
    ssl_certificate_key /www/server/panel/vhost/cert/your-domain.com/privkey.pem;

    access_log /www/wwwlogs/your-domain.access.log;
    error_log  /www/wwwlogs/your-domain.error.log;

    client_max_body_size 50m;

    location = /ticket {
        return 301 /ticket/;
    }

    location /ticket/ {
        alias /www/wwwroot/osticket/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/index.php?$query_string;
    }

    location /ticket/scp/ {
        alias /www/wwwroot/osticket/scp/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/scp/index.php?$query_string;
    }

    location /ticket/api/ {
        alias /www/wwwroot/osticket/api/;

        try_files $uri $uri/ /ticket/api/http.php?$query_string;
    }

    # 重点:支持 ajax.php/content/12/manage 这种 PATH_INFO 地址
    location ~ ^/ticket/(.+?\.php)(/.*)?$ {
        alias /www/wwwroot/osticket/$1;

        fastcgi_pass unix:/tmp/php-cgi-83.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME /www/wwwroot/osticket/$1;
        fastcgi_param SCRIPT_NAME /ticket/$1;
        fastcgi_param PATH_INFO $2;
        fastcgi_param PATH_TRANSLATED /www/wwwroot/osticket$2;
    }

    location ~* ^/ticket/include/ost-config\.php$ {
        deny all;
    }

    location ~* ^/ticket/setup/ {
        deny all;
    }

    location ~* ^/ticket/(sql|doc|scripts)/ {
        deny all;
    }

    location ~ /\. {
        deny all;
    }

    location ~* ^/ticket/.+\.(jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot)$ {
        alias /www/wwwroot/osticket/;
        expires 7d;
        access_log off;
    }
}

四、宝塔面板配置方式

1. 打开站点配置

进入宝塔:

网站 -> 找到主站 your-domain.com -> 设置 -> 配置文件

你会看到类似:

server {
    listen 80;
    server_name your-domain.com;
    root /www/wwwroot/your-domain.com;
    index index.php index.html index.htm;

    include enable-php-83.conf;
    include rewrite/your-domain.com.conf;

    # 其他配置...
}

你需要把 /ticket 相关配置加到当前 server {} 里面。

2. 宝塔中推荐插入的配置片段

把下面这段加入主站的 server {} 中:

# ==============================
# osTicket 子路径 /ticket 映射配置
# 访问路径:https://your-domain.com/ticket/
# 物理目录:/www/wwwroot/osticket
# ==============================

client_max_body_size 50m;

location = /ticket {
    return 301 /ticket/;
}

location /ticket/ {
    alias /www/wwwroot/osticket/;
    index index.php index.html index.htm;

    try_files $uri $uri/ /ticket/index.php?$query_string;
}

location /ticket/scp/ {
    alias /www/wwwroot/osticket/scp/;
    index index.php index.html index.htm;

    try_files $uri $uri/ /ticket/scp/index.php?$query_string;
}

location /ticket/api/ {
    alias /www/wwwroot/osticket/api/;

    try_files $uri $uri/ /ticket/api/http.php?$query_string;
}

# 重点:支持 ajax.php/content/12/manage 这种 PATH_INFO 地址
location ~ ^/ticket/(.+?\.php)(/.*)?$ {
    alias /www/wwwroot/osticket/$1;

    fastcgi_pass unix:/tmp/php-cgi-83.sock;
    fastcgi_index index.php;
    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME /www/wwwroot/osticket/$1;
    fastcgi_param SCRIPT_NAME /ticket/$1;
    fastcgi_param PATH_INFO $2;
    fastcgi_param PATH_TRANSLATED /www/wwwroot/osticket$2;
}

location ~* ^/ticket/include/ost-config\.php$ {
    deny all;
}

location ~* ^/ticket/setup/ {
    deny all;
}

location ~* ^/ticket/(sql|doc|scripts)/ {
    deny all;
}

location ~* ^/ticket/.+\.(jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot)$ {
    alias /www/wwwroot/osticket/;
    expires 7d;
    access_log off;
}

五、宝塔里最重要的注意点

1. /ticket 的 PHP 解析配置要放在通用 PHP 配置前面

宝塔站点配置里通常有这一行:

include enable-php-83.conf;

这个文件里面一般包含通用 PHP 解析规则,例如:

location ~ [^/]\.php(/|$) {
    # ...
}

你的 /ticket PHP 规则:

location ~ ^/ticket/(.+\.php)$ {
    ...
}

最好放在:

include enable-php-83.conf;

的前面。

原因是:Nginx 的正则 location 会按出现顺序匹配。 如果宝塔通用 PHP 规则先匹配了 /ticket/index.php,它会去主站目录下找:

/www/wwwroot/your-domain.com/ticket/index.php

但你的真实文件在:

/www/wwwroot/osticket/index.php

这样就会导致:

404
No input file specified
File not found

推荐结构:

server {
    listen 80;
    server_name your-domain.com;
    root /www/wwwroot/your-domain.com;

    # 先放 /ticket 的 alias 和 PHP 规则
    location = /ticket {
        return 301 /ticket/;
    }

    location /ticket/ {
        alias /www/wwwroot/osticket/;
        try_files $uri $uri/ /ticket/index.php?$query_string;
    }

    # 重点:支持 ajax.php/content/12/manage 这种 PATH_INFO 地址
    location ~ ^/ticket/(.+?\.php)(/.*)?$ {
        alias /www/wwwroot/osticket/$1;

        fastcgi_pass unix:/tmp/php-cgi-83.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME /www/wwwroot/osticket/$1;
        fastcgi_param SCRIPT_NAME /ticket/$1;
        fastcgi_param PATH_INFO $2;
        fastcgi_param PATH_TRANSLATED /www/wwwroot/osticket$2;
    }

    # 再放宝塔原有 PHP 配置
    include enable-php-83.conf;

    # 其他配置...
}

2. alias 后面必须带 /

这个是重点。

正确:

location /ticket/ {
    alias /www/wwwroot/osticket/;
}

错误:

location /ticket/ {
    alias /www/wwwroot/osticket;
}

少了最后的 /,容易导致静态资源、附件、CSS、JS 路径异常。

3. location /ticket/ 也必须带 /

正确:

location /ticket/ {
    alias /www/wwwroot/osticket/;
}

错误:

location /ticket {
    alias /www/wwwroot/osticket/;
}

建议单独加:

location = /ticket {
    return 301 /ticket/;
}

/ticket 自动跳到 /ticket/

六、PHP Socket 怎么确认?

你需要确认宝塔 PHP 的 socket。

执行:

ls /tmp/php-cgi-*.sock

可能看到:

/tmp/php-cgi-74.sock
/tmp/php-cgi-80.sock
/tmp/php-cgi-81.sock
/tmp/php-cgi-82.sock

如果你使用 PHP 8.1:

fastcgi_pass unix:/tmp/php-cgi-81.sock;

如果你使用 PHP 8.2:

fastcgi_pass unix:/tmp/php-cgi-82.sock;

如果你使用 PHP 8.3:

fastcgi_pass unix:/tmp/php-cgi-83.sock;

七、目录权限建议

假设 Nginx/PHP 运行用户是 www,执行:

chown -R www:www /www/wwwroot/osticket
find /www/wwwroot/osticket -type d -exec chmod 755 {} \;
find /www/wwwroot/osticket -type f -exec chmod 644 {} \;
chmod 640 /www/wwwroot/osticket/include/ost-config.php

如果附件目录、上传目录报权限错误,再检查 osTicket 后台的附件存储配置。

八、安装完成后的安全处理

osTicket 安装完成后,建议删除安装目录:

rm -rf /www/wwwroot/osticket/setup

即使没有删除,Nginx 里也已经禁止访问:

location ~* ^/ticket/setup/ {
    deny all;
}

配置文件也禁止外部访问:

location ~* ^/ticket/include/ost-config\.php$ {
    deny all;
}

九、可选:如果主站统一设置了 CSP

如果你的主站配置里有类似:

add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval';";

并且 osTicket 在 /ticket/ 下出现 JS、Worker、blob、data 相关报错,可以给 /ticket/ 单独放宽策略。

示例:

location /ticket/ {
    alias /www/wwwroot/osticket/;
    index index.php index.html index.htm;

    add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: data:; worker-src 'self' blob: data:; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self';" always;

    try_files $uri $uri/ /ticket/index.php?$query_string;
}

不过这个不是必须项。只有你确认 /ticket/ 受到主站 CSP 影响时再加。

十、检查配置

修改完成后,先测试 Nginx 配置:

nginx -t

如果显示:

syntax is ok
test is successful

再重载:

systemctl reload nginx

宝塔里也可以:

软件商店 -> Nginx -> 重载配置

十一、访问测试

前台:

https://your-domain.com/ticket/

后台:

https://your-domain.com/ticket/scp/

API:

https://your-domain.com/ticket/api/

测试静态资源是否正常:

https://your-domain.com/ticket/css/
https://your-domain.com/ticket/js/

实际是否能列目录不重要,关键是浏览器开发者工具里 CSS、JS 不要 404。

十二、最终推荐你在宝塔使用的核心配置

如果你的真实目录是:

/www/wwwroot/osticket

你的访问路径是:

/ticket

那么直接用这段:

# ==============================
# osTicket 子路径 /ticket 映射配置
# 访问路径:https://your-domain.com/ticket/
# 物理目录:/www/wwwroot/osticket
# ==============================

client_max_body_size 50m;

# /ticket 自动跳转到 /ticket/
location = /ticket {
    return 301 /ticket/;
}

# osTicket 前台入口
location /ticket/ {
    alias /www/wwwroot/osticket/;
    index index.php index.html index.htm;

    try_files $uri $uri/ /ticket/index.php?$query_string;
}

# osTicket 后台入口
location /ticket/scp/ {
    alias /www/wwwroot/osticket/scp/;
    index index.php index.html index.htm;

    try_files $uri $uri/ /ticket/scp/index.php?$query_string;
}

# osTicket API 入口
location /ticket/api/ {
    alias /www/wwwroot/osticket/api/;

    try_files $uri $uri/ /ticket/api/http.php?$query_string;
}

# 重点:解析 /ticket 下的 PHP 文件
# 同时支持 ajax.php/content/12/manage 这种 PATH_INFO 地址
location ~ ^/ticket/(.+?\.php)(/.*)?$ {
    alias /www/wwwroot/osticket/$1;

    fastcgi_pass unix:/tmp/php-cgi-83.sock;
    fastcgi_index index.php;
    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME /www/wwwroot/osticket/$1;
    fastcgi_param SCRIPT_NAME /ticket/$1;
    fastcgi_param PATH_INFO $2;
    fastcgi_param PATH_TRANSLATED /www/wwwroot/osticket$2;
}

# 禁止访问 osTicket 配置文件
location ~* ^/ticket/include/ost-config\.php$ {
    deny all;
}

# 安装完成后禁止访问 setup
location ~* ^/ticket/setup/ {
    deny all;
}

# 禁止访问敏感目录
location ~* ^/ticket/(sql|doc|scripts)/ {
    deny all;
}

# osTicket 静态资源缓存
location ~* ^/ticket/.+\.(jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot)$ {
    alias /www/wwwroot/osticket/;
    expires 7d;
    access_log off;
}

放置位置建议:

server {
    ...

    # 这里放 /ticket 配置
    # 必须放在 include enable-php-xx.conf 前面

    include enable-php-83.conf;

    ...
}

这样 /ticket 是访问路径,/www/wwwroot/osticket 是真实物理目录,二者不需要在同一个主站目录下。

 

 


 

本地EServer软件中的一个备份 —— Mac版本

server
{
    listen 80;
    server_name aiops.fuyo.com;
    index index.html index.htm index.php;
    root  /Users/albertwen/123;

    autoindex off;

    #301_START
    #301_END

    #HTTP_TO_HTTPS_START
    #HTTP_TO_HTTPS_END

    #SSL_START
    #SSL_END

    #REWRITE_START
    include vhosts/rewrite/aiops.fuyo.com_80.conf;
    #REWRITE_END

    #EXTRA_INFO_START
    #{"syncHosts":true}
    #EXTRA_INFO_END

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

    # 排除 /ticket/ 前缀,避免抢占 osTicket 的 alias location
    # (否则 .gif/.jpg 等会落到 server root /Users/albertwen/123 下导致 404)
    # location ~ ^(?!/ticket/).+\.(gif|jpg|jpeg|png|bmp|swf)$
    # {
    #     expires      1d;
    #     error_log /dev/null;
    #     access_log off;
    # }

    # 排除 /ticket/ 前缀,避免抢占 osTicket 的 alias location
    # (否则 .js/.css 会落到 server root /Users/albertwen/123 下导致 404)
    # location ~ ^(?!/ticket/).+\.(js|css)$
    # {
    #     expires      1h;
    #     error_log /dev/null;
    #     access_log off;
    # }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    access_log  logs/aiops.fuyo.com_80.access.log;
    error_log  logs/aiops.fuyo.com_80.error.log;

    # ===================================
    # DIC智能运维平台
    # ===================================
    # 前端页面
    # ~*:正则,且大小写不敏感
    location ~* /workbench/api/(.*) {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:30901/api/$1?$args;
    }
    # 后端接口
    # ^~:固定前缀,命中就锁定,绕过正则
    location ^~ /workbench {
        alias  /Users/albertwen/www/projects/java/DevOps/Fuyo-ITOps-Deploy/Fuyo-ITOps/Web/dist/;
    }

    # ===================================
    # 【扩展】工单管理系统
    # ===================================
    client_max_body_size 50m;

    # /ticket 自动跳转到 /ticket/
    location = /ticket {
        return 301 /ticket/;
    }

    # osTicket 前台入口
    location /ticket/ {
        alias /Users/albertwen/www/projects/java/DevOps/Fuyo-osTicket/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/index.php?$query_string;
    }

    # osTicket 后台入口
    location /ticket/scp/ {
        alias /Users/albertwen/www/projects/java/DevOps/Fuyo-osTicket/scp/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/scp/index.php?$query_string;
    }

    # osTicket API 入口
    location /ticket/api/ {
        alias /Users/albertwen/www/projects/java/DevOps/Fuyo-osTicket/api/;

        try_files $uri $uri/ /ticket/api/http.php?$query_string;
    }

    # 重点:解析 /ticket 下的 PHP 文件
    # 同时支持 ajax.php/content/12/manage 这种 PATH_INFO 地址
    location ~ ^/ticket/(.+?\.php)(/.*)?$ {
        alias /Users/albertwen/www/projects/java/DevOps/Fuyo-osTicket/$1;

        fastcgi_pass unix:/tmp/php-cgi-8.4.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME /Users/albertwen/www/projects/java/DevOps/Fuyo-osTicket/$1;
        fastcgi_param SCRIPT_NAME /ticket/$1;
        fastcgi_param PATH_INFO $2;
        fastcgi_param PATH_TRANSLATED /Users/albertwen/www/projects/java/DevOps/Fuyo-osTicket$2;
    }

    # 禁止访问 osTicket 配置文件
    location ~* ^/ticket/include/ost-config\.php$ {
        deny all;
    }

    # 安装完成后禁止访问 setup
    location ~* ^/ticket/setup/ {
        deny all;
    }

    # 禁止访问敏感目录
    location ~* ^/ticket/(sql|doc|scripts)/ {
        deny all;
    }

    # osTicket 静态资源缓存
    # 正则 location 下 alias 必须用捕获组映射路径,否则文件名丢失导致 404
    # 例:/ticket/scp/css/login.css -> $1=scp/css/login.css -> .../Extend-osTicket/scp/css/login.css
    # location ~* ^/ticket/(.*\.(?:jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot))$ {
    #     alias /Users/albertwen/www/projects/java/DevOps/Fuyo-osTicket/$1;
    #     expires 7d;
    #     access_log off;
    # }

}

本地EServer软件中的一个备份 —— Windows10版本

server
{
    listen 80;
    listen 443 ssl;
    server_name aiops.fuyo.com;
    index index.html index.htm index.php;
    root D:/software/EServer-data/childApp/server/nginx/html;

    ssl_certificate D:/software/EServer-data/etc/nginx/conf/ssl/aiops.fuyo.com.crt;
    ssl_certificate_key D:/software/EServer-data/etc/nginx/conf/ssl/aiops.fuyo.com.key;
    ssl_protocols TLSv1.2 TLSv1.3;

    autoindex off;

    location = /ticket {
        return 301 /ticket/;
    }

    location /ticket/ {
        alias D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket/;
        index index.php;
        try_files $uri $uri/ /ticket/index.php?$query_string;
    }

    location ~ ^/ticket/(include|\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md) {
        return 403;
    }

    location ~ ^/ticket/(.+\.php)(/.*)?$ {
        fastcgi_pass 127.0.0.1:9015;
        fastcgi_index index.php;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        fastcgi_param SCRIPT_FILENAME D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket/$1;
        fastcgi_param SCRIPT_NAME /ticket/$1;
        fastcgi_param PATH_INFO $2;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param REQUEST_URI $request_uri;
        fastcgi_param DOCUMENT_URI $document_uri;
        fastcgi_param DOCUMENT_ROOT D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param REQUEST_SCHEME $scheme;
        fastcgi_param HTTPS $https if_not_empty;
        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param REDIRECT_STATUS 200;
    }

    # osTicket rewrite rules for sub-path deployment.
    location ~ ^/ticket/api/(.*)$ {
        alias D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket/api/$1;
        try_files $uri $uri/ /ticket/api/http.php/$1?$query_string;
    }

    location ~ ^/ticket/pages/(.*)$ {
        alias D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket/pages/$1;
        try_files $uri $uri/ /ticket/pages/index.php/$1?$query_string;
    }

    location ~ ^/ticket/scp/apps/(.*)$ {
        alias D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket/scp/apps/$1;
        try_files $uri $uri/ /ticket/scp/apps/dispatcher.php/$1?$query_string;
    }

    location ~ ^/ticket/(.+\.(gif|jpg|jpeg|png|bmp|swf))$ {
        alias D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket/$1;
        expires 1d;
        error_log nul;
        access_log off;
    }

    location ~ ^/ticket/(.+\.(js|css))$ {
        alias D:/www/java/Projects/fuyo-ai/DevOps/Fuyo-osTicket/$1;
        expires 1h;
        error_log nul;
        access_log off;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    access_log logs/aiops.fuyo.com_80.access.log;
    error_log logs/aiops.fuyo.com_80.error.log;
}

测试环境宝塔面板中的一个备份

server
{
    listen 80;
    listen 443 ssl;
    listen 443 quic;
    http2 on;
    server_name aiops.xxx.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/aiops.xxx.com;
    
    #CERT-APPLY-CHECK--START
    # 用于SSL证书申请时的文件验证相关配置 -- 请勿删除
    include /www/server/panel/vhost/nginx/well-known/aiops.xxx.com.conf;
    #CERT-APPLY-CHECK--END
    include /www/server/panel/vhost/nginx/extension/aiops.xxx.com/*.conf;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    ssl_certificate    /www/server/panel/vhost/cert/aiops.xxx.com/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/aiops.xxx.com/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA2xxxxxxxES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_tickets on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    add_header Alt-Svc 'quic=":443"; h3=":443";xxx h3-29=":443"; h3-27=":44xxxxxxxx3";h48=":443"; h3-Q046=":443"; h3-Q043=":443"';
    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-83.conf;
    #PHP-INFO-END

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

    # 禁止访问的敏感文件
    location ~* (\.user.ini|\.htaccess|\.htpasswd|\.env.*|\.project|\.bashrc|\.bash_profile|\.bash_logout|\.DS_Store|\.gitignore|\.gitattributes|LICENSE|README\.md|CLAUDE\.md|CHANGELOG\.md|CHANGELOG|CONTRIBUTING\.md|TODO\.md|FAQ\.md|composer\.json|composer\.lock|package(-lock)?\.json|yarn\.lock|pnpm-lock\.yaml|\.\w+~|\.swp|\.swo|\.bak(up)?|\.old|\.tmp|\.temp|\.log|\.sql(\.gz)?|docker-compose\.yml|docker\.env|Dockerfile|\.csproj|\.sln|Cargo\.toml|Cargo\.lock|go\.mod|go\.sum|phpunit\.xml|phpunit\.xml|pom\.xml|build\.gradl|pyproject\.toml|requirements\.txt|application(-\w+)?\.(ya?ml|properties))$
    {
        return 404;
    }
    
    # 禁止访问的敏感目录
    location ~* /(\.git|\.svn|\.bzr|\.vscode|\.claude|\.idea|\.ssh|\.github|\.npm|\.yarn|\.pnpm|\.cache|\.husky|\.turbo|\.next|\.nuxt|node_modules|runtime)/ {
        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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    # {
    #     expires      30d;
    #     error_log /dev/null;
    #     access_log /dev/null;
    # }

    # location ~ .*\.(js|css)?$
    # {
    #     expires      12h;
    #     error_log /dev/null;
    #     access_log /dev/null;
    # }
    access_log  /www/wwwlogs/aiops.xxx.com.log;
    error_log  /www/wwwlogs/aiops.xxx.com.error.log;
    
    
    # ===================================
    # DIC智能运维平台
    # ===================================
    # 前端页面
    # ~*:正则,且大小写不敏感
    location ~* /workbench/api/(.*) {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:30901/api/$1?$args;
    }
    # 后端接口
    # ^~:固定前缀,命中就锁定,绕过正则
    location ^~ /workbench {
        alias  /Users/albertwen/www/projects/java/Fuyo-ITOps/Web/dist/;
    }

    # ===================================
    # 【扩展】工单管理系统
    # ===================================
    client_max_body_size 50m;

    # /ticket 自动跳转到 /ticket/
    location = /ticket {
        return 301 /ticket/;
    }

    # osTicket 前台入口
    location /ticket/ {
        alias /www/wwwroot/aiops.xxx.com/Fuyo-osTicket/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/index.php?$query_string;
    }

    # osTicket 后台入口
    location /ticket/scp/ {
        alias /www/wwwroot/aiops.xxx.com/Fuyo-osTicket/scp/;
        index index.php index.html index.htm;

        try_files $uri $uri/ /ticket/scp/index.php?$query_string;
    }

    # osTicket API 入口
    location /ticket/api/ {
        alias /www/wwwroot/aiops.xxx.com/Fuyo-osTicket/api/;

        try_files $uri $uri/ /ticket/api/http.php?$query_string;
    }

    # 重点:解析 /ticket 下的 PHP 文件
    # 同时支持 ajax.php/content/12/manage 这种 PATH_INFO 地址
    location ~ ^/ticket/(.+?\.php)(/.*)?$ {
        alias /www/wwwroot/aiops.xxx.com/Fuyo-osTicket/$1;

        fastcgi_pass unix:/tmp/php-cgi-83.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME /www/wwwroot/aiops.xxx.com/Fuyo-osTicket/$1;
        fastcgi_param SCRIPT_NAME /ticket/$1;
        fastcgi_param PATH_INFO $2;
        fastcgi_param PATH_TRANSLATED /www/wwwroot/aiops.xxx.com/Fuyo-osTicket$2;
    }

    # 禁止访问 osTicket 配置文件
    location ~* ^/ticket/include/ost-config\.php$ {
        deny all;
    }

    # 安装完成后禁止访问 setup
    location ~* ^/ticket/setup/ {
        deny all;
    }

    # 禁止访问敏感目录
    location ~* ^/ticket/(sql|doc|scripts)/ {
        deny all;
    }

    # osTicket 静态资源缓存
    # 正则 location 下 alias 必须用捕获组映射路径,否则文件名丢失导致 404
    # 例:/ticket/scp/css/login.css -> $1=scp/css/login.css -> .../Extend-osTicket/scp/css/login.css
    location ~* ^/ticket/(.*\.(?:jpg|jpeg|png|gif|ico|css|js|svg|webp|woff|woff2|ttf|eot))$ {
        alias /www/wwwroot/aiops.xxx.com/Fuyo-osTicket/$1;
        expires 7d;
        access_log off;
    }

}