简体   繁体   中英

Nginx no file found but picking information from mysql

Hey i have problem i install script on xampp and nginx webservers. On xampp pefrectly working on nginx works only homepage other links not working because nginx can't find file i get 404 error but links like /login /singup picking information from database mysql and file don't exist like login.php singup.php but nginx try search file and i get error 404 what need to do to fix it? in xampp i don't get that error

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 script

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

You have a rewrite rule in your htaccess that redirects all requests (that doesn't exist on the server) to your index.php file:

From your current htaccess:

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

Since nginx doesn't use htaccess files, you need to add the same rule to your nginx-server config.

This nginx-rule should do the same thing as the htaccess-rewrite:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM