Nginx找不到文件,但从mysql中选择信息

时间:2018-12-28 14:19:56

标签: php mysql nginx

嘿,我在xampp和Nginx Web服务器上安装脚本时遇到问题。 在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

1 个答案:

答案 0 :(得分:0)

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

根据您当前的htaccess:

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

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

此nginx规则应执行与htaccess-rewrite相同的操作:

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