Skip to main content

常见问题

常见伪静态配置

ThinkPHP5

** 展开查看源码 **
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}

YII2

** 展开查看源码 for rageframe2 **
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /backend {
try_files $uri $uri/ /backend/index.php$is_args$args;
}
location /api {
try_files $uri $uri/ /api/index.php$is_args$args;
}
location /merchant {
try_files $uri $uri/ /merchant/index.php$is_args$args;
}
location /merapi {
try_files $uri $uri/ /merapi/index.php$is_args$args;
}
location /html5 {
try_files $uri $uri/ /html5/index.php$is_args$args;
}
location /oauth2 {
try_files $uri $uri/ /oauth2/index.php$is_args$args;
}

location ~* ^/attachment/.*\.(php|php5)$
{
deny all;
}

Laravel

** 展开查看源码 **
server {
listen 80;
server_name example.com;
root /srv/example.com/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

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

error_page 404 /index.php;

location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.(?!well-known).* {
deny all;
}
}

伪静态为题导致前台页面无法访问

问题描述

前台页面除首页外其他页面无法直接通过地址栏url访问,直接访问报404 环境:Yii2、Nginx、前台使用vue

原因

nginx伪静态配置不对

Nginx配置文件参考

有问题的配置文件

location / {
try_files $uri $uri/ /index.php$is_args$args;
}

相对完美的配置文件

location / {
try_files $uri $uri/ /index.html?s=$is_args$args;
}