1

I've got this website on nginx, it's a php script for an image site.

The problem is that whenever I click on a link on the homepage it gives me a 404. I can access the homepage and it shows the last images and I can access and use the admin panel so the script or it's installation is not the problem.

I believe the problem is with my nginx.conf file but it's my first time using it and I can't find the problem. I'm pretty sure it's some easy thing on the http part.

Can anyone see what the problem is?

I attach the nginx.conf.

user www-data;
worker_processes 5;
pid /var/run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
    # server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

  index index.php;

##Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
 }

I add the sites-enabled and sites-available files for the site in question.

SITES ENABLED FILE

server {
      listen *:80;


    server_name MYSITE.com ;

    root   /var/www/MYSITE.com/web;



    index index.php;


    location ~ \.shtml$ {
        ssi on;
    }


    error_log /var/log/ispconfig/httpd/MYSITE.com/error.log;
    access_log /var/log/ispconfig/httpd/MYSITE.com/access.log combined;

    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location /stats {

        index index.html index.php;
        auth_basic "Members Only";
        auth_basic_user_file /var/www/clients/client0/web1/web/stats/.htpasswd_stats;
    }

    location ^~ /awstats-icon {
        alias /usr/share/awstats/icon;
    }

    location ~ \.php$ {
        try_files /446853f6175b4ee703d1115b71d6c0c9.htm @php;
    }

    location @php {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }

    location /cgi-bin/ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        root /var/www/clients/client0/web1;
        gzip off;
        fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }






}

SITES AVAILABLE FILE

server {
    listen *:80;


    server_name MYSITE.com ;

    root   /var/www/MYSITE.com/web;



    index index.php;


    location ~ \.shtml$ {
        ssi on;
    }


    error_log /var/log/ispconfig/httpd/MYSITE.com/error.log;
    access_log /var/log/ispconfig/httpd/MYSITE.com/access.log combined;

    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location /stats {

        index index.html index.php;
        auth_basic "Members Only";
        auth_basic_user_file /var/www/clients/client0/web1/web/stats/.htpasswd_stats;
    }

    location ^~ /awstats-icon {
        alias /usr/share/awstats/icon;
    }

    location ~ \.php$ {
        try_files /446853f6175b4ee703d1115b71d6c0c9.htm @php;
    }

    location @php {

        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }

    location /cgi-bin/ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        root /var/www/clients/client0/web1;
        gzip off;
        fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }






}

I add the last lines of /var/log/ispconfig/httpd/MYSITE.com/error.log to my post. (It's a pain to edit the domain so I'll just leave it there and edit the question later)

2013/08/29 03:20:28 [error] 30672#0: *513 open() "/var/www/cosplayde.com/web/asdasd" failed (2: No such file or directory), client: 66.249.75.229, server: cosplayde.com, request: "GET /asdasd HTTP/1.1", host: "cosplayde.com"
2013/08/29 03:20:29 [error] 30672#0: *513 open() "/var/www/cosplayde.com/web/hebi" failed (2: No such file or directory), client: 66.249.75.229, server: cosplayde.com, request: "GET /hebi HTTP/1.1", host: "cosplayde.com"
2013/08/29 03:20:42 [error] 30672#0: *514 open() "/var/www/cosplayde.com/web/asdsa" failed (2: No such file or directory), client: 66.249.75.229, server: cosplayde.com, request: "GET /asdsa HTTP/1.1", host: "cosplayde.com"
2013/08/29 03:21:43 [error] 30672#0: *515 open() "/var/www/cosplayde.com/web/casper" failed (2: No such file or directory), client: 66.249.75.229, server: cosplayde.com, request: "GET /casper HTTP/1.1", host: "cosplayde.com"
2013/08/29 05:26:47 [error] 30672#0: *544 open() "/var/www/cosplayde.com/web/apple-touch-icon.png" failed (2: No such file or directory), client: 66.249.75.229, server: cosplayde.com, request: "GET /apple-touch-icon.png HTTP/1.1", host: "cosplayde.com"
2013/08/29 05:27:16 [error] 30672#0: *545 open() "/var/www/cosplayde.com/web/apple-touch-icon-precomposed.png" failed (2: No such file or directory), client: 66.249.75.229, server: cosplayde.com, request: "GET /apple-touch-icon-precomposed.png HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:43:52 [error] 30670#0: *688 open() "/var/www/cosplayde.com/web/3" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /3 HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:44:20 [error] 30670#0: *689 open() "/var/www/cosplayde.com/web/2" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /2 HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:44:55 [error] 30670#0: *690 open() "/var/www/cosplayde.com/web/5" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /5 HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:45:29 [error] 30670#0: *692 open() "/var/www/cosplayde.com/web/rss" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /rss HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:46:04 [error] 30670#0: *693 open() "/var/www/cosplayde.com/web/hebi" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /hebi HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:46:38 [error] 30670#0: *694 open() "/var/www/cosplayde.com/web/asdsa" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /asdsa HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:47:12 [error] 30670#0: *695 open() "/var/www/cosplayde.com/web/dolina" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /dolina HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:47:47 [error] 30670#0: *696 open() "/var/www/cosplayde.com/web/touhou" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /touhou HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:48:22 [error] 30670#0: *697 open() "/var/www/cosplayde.com/web/kyuutsui" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /kyuutsui HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:48:58 [error] 30670#0: *698 open() "/var/www/cosplayde.com/web/cosplay-sexy" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /cosplay-sexy HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:49:34 [error] 30670#0: *699 open() "/var/www/cosplayde.com/web/submit_images" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /submit_images HTTP/1.1", host: "cosplayde.com"
2013/08/29 16:50:16 [error] 30670#0: *701 open() "/var/www/cosplayde.com/web/category/default" failed (2: No such file or directory), client: 66.249.72.229, server: cosplayde.com, request: "GET /category/default HTTP/1.1", host: "cosplayde.com"
2013/08/30 05:38:23 [error] 30669#0: *916 open() "/var/www/cosplayde.com/web/category/default" failed (2: No such file or directory), client: 120.151.131.182, server: cosplayde.com, request: "GET /category/default HTTP/1.1", host: "cosplayde.com", referrer: "http://cosplayde.com/"
2013/08/30 05:39:33 [error] 30669#0: *916 open() "/var/www/cosplayde.com/web/rss" failed (2: No such file or directory), client: 120.151.131.182, server: cosplayde.com, request: "GET /rss HTTP/1.1", host: "cosplayde.com", referrer: "http://cosplayde.com/"
2013/08/30 06:05:32 [error] 30669#0: *940 open() "/var/www/cosplayde.com/web/5" failed (2: No such file or directory), client: 200.126.222.14, server: cosplayde.com, request: "GET /5 HTTP/1.1", host: "cosplayde.com", referrer: "http://cosplayde.com/"
2013/08/30 06:17:24 [error] 10945#0: *1 open() "/var/www/cosplayde.com/web/5" failed (2: No such file or directory), client: 190.193.156.31, server: cosplayde.com, request: "GET /5 HTTP/1.1", host: "cosplayde.com", referrer: "http://cosplayde.com/"
2013/08/30 06:21:57 [error] 11863#0: *47 open() "/var/www/cosplayde.com/web/5" failed (2: No such file or directory), client: 200.126.222.14, server: cosplayde.com, request: "GET /5 HTTP/1.1", host: "cosplayde.com", referrer: "http://cosplayde.com/"
2013/08/30 06:22:10 [error] 11863#0: *47 open() "/var/www/cosplayde.com/web/kyuutsui" failed (2: No such file or directory), client: 200.126.222.14, server: cosplayde.com, request: "GET /kyuutsui HTTP/1.1", host: "cosplayde.com", referrer: "http://cosplayde.com/"
  • Did you set the file permissions recursively? – Sterling Archer Aug 27 '13 at 01:36
  • I believe i did. All directories are 755 and all files are 644 (except a couple folders that need to be 777 for the script to work) – user2719827 Aug 27 '13 at 01:48
  • But it still gives out 404 for all onpage links. I just checked the error log and I see this. 2013/08/27 04:25:37 [error] 29071#0: *555 open() "/var/www/MYSITE.com/web/FAILEDURL" failed (2: No such file or directory), client: 190.193.156.31, server: MYSITE.com, request: "GET /FAILEDURL HTTP/1.1", host: "MYSITE.com", referrer: "http://MYSITE.com/" – user2719827 Aug 27 '13 at 02:30
  • please share the virtual host config file, not the nginx, ones that are usually in `sites-enabled` and `sites-available` – Mohammad AbuShady Aug 27 '13 at 06:13
  • Related: https://stackoverflow.com/questions/12924896/rewrite-all-requests-to-index-php-with-nginx – Jesse Nickles Sep 10 '22 at 20:44

1 Answers1

0

Is your site a wordpress site? Knowing which php application you are running will help people to give you more accurate feedback.

Just based on your site configs and your description,

  1. remove the line try_files $uri =404; below location @php
  2. add following lines before location ~ \.php$:

    location / {
       try_files $uri =404;
    }    
    

HTH

number5
  • 15,913
  • 3
  • 54
  • 51
  • Just tried it (made the changes on sites-enabled, didn't work, removed the changes, made the changes on sites-available, didn't work, removed the changes) I got 404 when trying to enter the homepage after those changes. After the removal the homepage and admin panel started working again (I still can't click on any onpage link because I get a 404). The site is not a wordpress website. It's a script on php for an image site. – user2719827 Aug 30 '13 at 04:23
  • This might be a dumb question but did you restart nginx after you made changes to the config files? Also what in sites-enabled should be just a symlink to file in sites-availalbe. If nothing change after your made the changes, could you post last 20 lines of /var/log/ispconfig/httpd/MYSITE.com/error.log to your main post? – number5 Aug 30 '13 at 04:41
  • I have added the last 20 lines of said log to the main post. I did restart nginx after each change. I'm not sure how to respond the symlink question. – user2719827 Aug 31 '13 at 03:04
  • None of the requests in your log except for apple-touch-icon.png/apple-touch-icon-precomposed.png looks like a requests for images – number5 Aug 31 '13 at 07:30