要在Nginx环境中配置WeCenter的伪静态规则,请按照以下步骤操作:
在Nginx的站点配置文件中(通常位于/etc/nginx/sites-available/
目录下),找到您的WeCenter站点配置,在server
块中添加以下规则:
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(gif|jpg|jpeg|png|css|js|ico|swf|flv)$ {
expires 30d;
access_log off;
}
location ~ /\.ht {
deny all;
}
在同一个配置文件中,添加以下WeCenter专用的伪静态规则:
if (!-e $request_filename) {
rewrite ^/([^/]*)/?$ /index.php?$1 last;
rewrite ^/([^/]*)/([^/]*)/?$ /index.php?$1/$2 last;
rewrite ^/([^/]*)/([^/]*)/(.*)/?$ /index.php?$1/$2/$3 last;
}
以下是包含伪静态规则的完整server块示例:
server {
listen 80;
server_name yourdomain.com;
root /var/www/wecenter;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(gif|jpg|jpeg|png|css|js|ico|swf|flv)$ {
expires 30d;
access_log off;
}
location ~ /\.ht {
deny all;
}
if (!-e $request_filename) {
rewrite ^/([^/]*)/?$ /index.php?$1 last;
rewrite ^/([^/]*)/([^/]*)/?$ /index.php?$1/$2 last;
rewrite ^/([^/]*)/([^/]*)/(.*)/?$ /index.php?$1/$2/$3 last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
测试Nginx配置是否正确:
sudo nginx -t
重新加载Nginx配置:
sudo systemctl reload nginx
完成Nginx配置后,登录WeCenter后台,进行以下设置: 1. 进入"系统设置" > "站点设置" 2. 找到"URL 路由设置"或"伪静态设置" 3. 启用伪静态功能
fastcgi_pass
路径如果您遇到任何问题,可以检查Nginx错误日志获取更多信息:
tail -f /var/log/nginx/error.log