php - Nginx 找不到文件但从 mysql 中获取信息

标签 php mysql nginx

嘿,我在 xampp 和 nginx 网络服务器上安装脚本时遇到问题。 在 xampp peflectly 上,在 nginx 上工作仅适用于主页,其他链接不起作用,因为 nginx 找不到文件,我收到 404 错误,但像/login/singup 这样从数据库 mysql 和文件中选取信息的链接不存在,如 login.php singup.php 但nginx 尝试搜索文件,但出现错误 404,需要做什么来修复它?在 xampp 中我没有收到该错误

server {
    listen 80;
    listen 443 ssl http2;
    server_name hiddenlink.com;

root   /var/www/yt/ig;
index index.php;

location / {
    autoindex on;
    root   /var/www/yt/ig;
    index index.php;

}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /var/www/yt;
}
error_page 404 /404.html;
    location = /404.html {
            root /var/www/yt;
            internal;
    }

#location / {
#try_files $uri $uri/ /index.php?q=$uri$args;
#}

location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
    return 404;
}
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    #fastcgi_connect_timeout 300s;
    fastcgi_read_timeout 120s;
    #fastcgi_send_timeout 300s;

    }

location ~ /\.ht {
    deny all;
}


if ($http_user_agent ~ "libwww-perl") {
    set $block_user_agents 1;
}

}

.htaccess脚本

RewriteEngine On

#RewriteCond %{HTTPS} off
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options +FollowSymLinks
Options -Indexes

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L,QSA]



# Performace optimization

# BEGIN Compress text files
<ifModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
  AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
  AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
  AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
  AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
  AddOutputFilterByType DEFLATE font/truetype font/opentype
</ifModule>
# END Compress text files

# BEGIN Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 5 seconds"
  ExpiresByType image/x-icon "access plus 31536000 seconds"
  ExpiresByType image/jpeg "access plus 31536000 seconds"
  ExpiresByType image/png "access plus 31536000 seconds"
  ExpiresByType image/gif "access plus 31536000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 31536000 seconds"
  ExpiresByType text/css "access plus 31536000 seconds"
  ExpiresByType text/javascript "access plus 31536000 seconds"
  ExpiresByType application/javascript "access plus 31536000 seconds"
  ExpiresByType application/x-javascript "access plus 31536000 seconds"
</ifModule>
# END Expire headers

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch ".(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "public"
  </filesMatch>
  <filesMatch ".(css)$">
    Header set Cache-Control "public"
  </filesMatch>
  <filesMatch ".(js)$">
    Header set Cache-Control "private"
  </filesMatch>
  <filesMatch ".(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
  </filesMatch>

  <filesMatch ".(woff|woff2|ttf|otf|eot)$">
    Header set Cache-Control "max-age=31536000 private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers

最佳答案

您的 htaccess 中有一个重写规则,它将所有请求(服务器上不存在的请求)重定向到您的 index.php 文件:

从您当前的htaccess:

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L,QSA]

由于 nginx 不使用 htaccess 文件,因此您需要将相同的规则添加到 nginx-server 配置中。

这个 nginx-rule 应该做与 htaccess-rewrite 相同的事情:

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

关于php - Nginx 找不到文件但从 mysql 中获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53959960/

相关文章:

php - 值从 php 到存储过程

php - 反序列化有时会返回 false

php - FosRestBundle PATCH 操作 + 具有 NotBlank 约束的实体字段

php - NGINX 'Access-Control-Allow-Origin' header 包含多个值

php - 解析 PUT 请求的参数时出错

javascript - 当时钟到达 '0' 时停止 JavaScript 定时器

php - 使用 Zend Framework 登录后如何更新 guest 用户的购物车

java - QueryDsl SQL - 左连接子查询

nginx - Docker群以Nginx作为缓存:502错误的网关

wordpress - Nginx和Varnish连接错误