nginx找不到文件,但正在从mysql中提取信息

4si2a6ki  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(307)

嘿,我有问题,我在xampp和nginx服务器上安装脚本。在xampp上,直接使用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
jqjz2hbq

jqjz2hbq1#

htaccess中有一个重写规则,可以将所有请求(服务器上不存在的请求)重定向到 index.php 文件:
从您当前的访问权限:

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

由于nginx不使用htaccess文件,因此需要将相同的规则添加到nginx服务器配置中。
此nginx规则应执行与htaccess重写相同的操作:

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

相关问题