nginx1.8 在配置文件中添加了配置代码,访问URL不加index.php的路由,报404

nginx1.8 在配置文件中添加了配置代码,访问URL不加index.php的路由,报404

已经在nginx中添加了官方代码,不加index.php,除了/路由不报错,其他路由依旧报404,加了的话正常访问。
官方代码如下

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

有大神告知一下吗

讨论数量: 19

部署《Laravel 8 中文文档》

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;
    }
}
2年前 评论
Chinago (楼主) 2年前
Chinago (楼主) 2年前
Su (作者) 2年前
Chinago (楼主) 2年前
Su (作者) 2年前
Chinago (楼主) 2年前
Chinago (楼主) 2年前
Chinago (楼主) 2年前
Chinago (楼主) 2年前
Su (作者) 2年前
Chinago (楼主) 2年前

server { listen 80; server_name _; autoindex on; index index.html index.htm index.php;

    root D:/softwera/phpEnv/server/nginx/html/;
    access_log  logs/access.log;
    location / {
    try_files $uri $uri/ /index.php?$query_string;
   }
    location = /favicon.ico {
        log_not_found off;
        access_log off;

    }
    # 将 [404] 错误交给 [/index.php] 处理,表示由 Laravel 渲染美观的错误页面。
    error_page 404 /index.php;
}

include vhosts/*.conf;

}

2年前 评论

你这配置如何解析的 php 语法??

PHP

你的路由文件呢???

2年前 评论
server {
         listen       80;
         server_name  www.11.cn;
         root  "D:/softwera/phpEnv/server/nginx/html/";
         index index.php index.html index.htm;
         location / {
            try_files $uri $uri/ /index.php?$query_string;
          }

         location ~ \.php$ {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
         }
}
2年前 评论

你的配置,缺少转发php-fpm的部分

location ~ \.php$ {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
}
2年前 评论
Chinago (楼主) 2年前

file

Laravel

这样子还是行哦,路由/首页不用加index.php,qw不加index.php,还是报404

@Su @IDLIFE

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!