我的知识记录

请问Nginx如何设置伪静态?

不同程序在不同运行环境下, apache 、nginx、iis下的伪静态规则都存在差异。 

以下只是举例,具体需要结合自己的网站程序配置

server {     listen 80;     server_name yourdomain.com;      root /var/www/yourdomain.com;     index index.html index.htm index.php;      location / {         try_files $uri $uri/ /index.php?$args;     }      location ~ \.php$ {         include snippets/fastcgi-php.conf;         fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你的 PHP 版本调整     }      # 通用伪静态规则     rewrite ^/archive/([0-9]{4})/([0-9]{2})/([0-9]{2})/$ /index.php?year=$1&month=$2&day=$3 last;     rewrite ^/category/(.*)/$ /index.php?category=$1 last;     rewrite ^/tag/(.*)/$ /index.php?tag=$1 last;     rewrite ^/page/([0-9]+)/$ /index.php?page=$1 last;     rewrite ^/post/([0-9]+)$ /index.php?post_id=$1 last; }

 

标签:Nginx如何设置指定ip访问-nginx如何设置开机自启-nginx如何设置首页不缓存-nginx如何设置后端uri为真实请求的uri-nginx如何设置超时

更新时间:2025-04-10 23:45:59

上一篇:请问dedecms列表页数据重复解决方法

下一篇:请问MySQL密码忘记怎么办?