Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Nginx 404

I'm trying to install vanilla forums but I keep on getting a 404 from nginx.

This is what I currently have set:

server_tokens off;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

server {
    listen 80;

    root /var/www/public;
    index index.php;

    server_name example.com 10.0.1.25;

    error_page 404 /404.html;
    error_page 500 /500.html;

    location /forum {
        # /index.php handler
        location ~* "^/index\.php(/|$)" {
        include fastcgi_params;
        fastcgi_param X_REWRITE 1;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        }

        location ~* "\.php(/|$)" {
            rewrite ^ /index.php$uri last;
        }

        try_files $uri $uri/ /index.php?p=$uri&$args;
    }
}

This is what fastcgi_params is set to:

    fastcgi_param   QUERY_STRING            $query_string;
    fastcgi_param   REQUEST_METHOD          $request_method;
    fastcgi_param   CONTENT_TYPE            $content_type;
    fastcgi_param   CONTENT_LENGTH          $content_length;

    fastcgi_param   SCRIPT_FILENAME         $request_filename;
    fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
    fastcgi_param   REQUEST_URI             $request_uri;
    fastcgi_param   DOCUMENT_URI            $document_uri;
    fastcgi_param   DOCUMENT_ROOT           $document_root;
    fastcgi_param   SERVER_PROTOCOL         $server_protocol;

    fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
    fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

    fastcgi_param   REMOTE_ADDR             $remote_addr;
    fastcgi_param   REMOTE_PORT             $remote_port;
    fastcgi_param   SERVER_ADDR             $server_addr;
    fastcgi_param   SERVER_PORT             $server_port;
    fastcgi_param   SERVER_NAME             $host;

    fastcgi_param   HTTPS                   $https if_not_empty;
    fastcgi_param PHP_VALUE "session.cookie_httponly=on;\n error_reporting=E_ALL;\n display_errors=on;";

    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param   REDIRECT_STATUS         200;

Can anyone help me fix this? Thanks

Answers

  • MinnitMinnit New
    edited December 2017

    I'm using nginx so htaccess wouldn't matter. htaccess would matter if I was using apache

  • R_JR_J Admin
    edited December 2017

    I'm no nginx wizard, but if you see 404 error, I would say that your "location" instructions are wrong. The fastcgi part would only be of interest if the php file couldn't be processed, wouldn't it?

    Based on some old posting here on the forum, I'm working with the following location instructions without any problems:

       location / {
            try_files $uri $uri/ @vanilla;
        }
    
        location @vanilla {
            rewrite ^/(.+)$ /index.php?p=$1 last;
        }
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php7-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    

    I've never used a location block, but using the above and mixing it with your content, I would advice trying the following

       location /forum {
            try_files $uri $uri/ @vanilla;
    
            location @vanilla {
                rewrite ^/(.+)$ /index.php?p=$1 last;
            }
    
            location ~ \.php$ {
                include fastcgi_params;
                fastcgi_param X_REWRITE 1;
                fastcgi_intercept_errors on;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            }
    
            location ~ /\.ht {
                deny all;
            }
        }
    

    I really don't know if you need to add fastcgi_split_path_info ^(.+\.php)(/.+)$; or if you have to leave out fastcgi_param X_REWRITE 1; or a mixture of both o.O

  • When I tried that I got this error: "nginx: [emerg] named location "@vanilla" can be on the server level only in /etc/nginx/sites-enabled/default:18"

    So I tried this:

    location /forum {
            try_files $uri $uri/ @vanilla;
    
            location ~ \.php$ {
                include fastcgi_params;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                #fastcgi_param X_REWRITE 1;
                fastcgi_intercept_errors on;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            }
    
            location ~ /\.ht {
                deny all;
            }
        }
    
        location @vanilla {
                rewrite ^/(.+)$ /forum/index.php?p=$1 last;
        }
    

    This configuration results in a 500 internal server error saying "Something has gone wrong.
    We've run into a problem and are unable to handle this request right now.
    Please check back in a little while."

    If I leave out fastcgi_split_path_info, it still gives 500 internal server error. If I include X_REWRITE, I get a redirect loop (even if fastcgi_split_path_info is excluded)

    On the bright side I'm not getting a 404 anymore, though a 500 is not that much better.

    Any ideas on how I can fix it?

    Thanks again

  • @Minnit said:
    On the bright side I'm not getting a 404 anymore, though a 500 is not that much better.

    Add this to your server configuration:

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

    The error log should be able to help you

  • @R_J

    I tried that and the access_log works, but nothing is displayed in the error_log.

    This is what I see in the access_log:

    10.0.1.26 - - [20/Dec/2017:18:39:08 +0000] "GET /forum/dashboard/setup HTTP/1.1" 500 719 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    10.0.1.26 - - [20/Dec/2017:18:39:08 +0000] "GET /forum/applications/dashboard/design/error.css HTTP/1.1" 200 250 "http://10.0.1.25/forum/dashboard/setup" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    10.0.1.26 - - [20/Dec/2017:18:40:55 +0000] "GET /forum/dashboard/setup HTTP/1.1" 500 719 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    10.0.1.26 - - [20/Dec/2017:18:40:55 +0000] "GET /favicon.ico HTTP/1.1" 200 11141 "http://10.0.1.25/forum/dashboard/setup" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    10.0.1.26 - - [20/Dec/2017:18:42:08 +0000] "GET /forum/dashboard/setup HTTP/1.1" 500 719 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    10.0.1.26 - - [20/Dec/2017:18:42:08 +0000] "GET /favicon.ico HTTP/1.1" 200 11141 "http://10.0.1.25/forum/dashboard/setup" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    10.0.1.26 - - [20/Dec/2017:18:42:31 +0000] "GET /forum/dashboard/setup HTTP/1.1" 500 719 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    10.0.1.26 - - [20/Dec/2017:18:42:31 +0000] "GET /favicon.ico HTTP/1.1" 200 11141 "http://10.0.1.25/forum/dashboard/setup" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
    

    Any ideas?

  • @R_J

    This got caught in the spam queue.

  • Not quite sure what is happening. Please do the following two things:
    1. Add $Configuration['Debug'] = true; to your /conf/config.php
    2. Edit /index.php and change ini_set('display_errors', 0); to ini_set('display_errors', 1);

    I hope that it will show more information on failure...

  • MinnitMinnit New
    edited December 2017

    @R_J

    This does give me more information:

    An error occurred while attempting to connect to the database
    SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
    The error occurred on or near: /var/www/public/forum/library/database/class.database.php
    171:             if ($Timeout) {
    172:                 throw new Exception(errorMessage('Timeout while connecting to the database', $this->ClassName, 'Connection', $ex->getMessage()), 504);
    173:             }
    174: 
    175:             throw new Exception(errorMessage('An error occurred while attempting to connect to the database', $this->ClassName, 'Connection', $ex->getMessage()), 500);
    176:         }
    177: 
    178:         return $PDO;
    179:     }
    

    Backtrace:
    [/var/www/public/forum/library/database/class.database.php:102] Gdn_Database->newPDO();
    [/var/www/public/forum/library/database/class.database.php:502] Gdn_Database->connection();
    [/var/www/public/forum/library/database/class.database.php:368] Gdn_Database->slave();
    [/var/www/public/forum/library/database/class.sqldriver.php:1663] Gdn_Database->query();
    [/var/www/public/forum/library/database/class.sqldriver.php:884] Gdn_SQLDriver->query();
    [/var/www/public/forum/library/core/class.authenticationprovidermodel.php:168] Gdn_SQLDriver->getWhere();
    [/var/www/public/forum/library/core/class.authenticationprovidermodel.php:57] Gdn_AuthenticationProviderModel::getWhereStatic();
    [/var/www/public/forum/library/core/functions.render.php:1146] Gdn_AuthenticationProviderModel::getDefault();
    [/var/www/public/forum/library/core/class.theme.php:341] PHP::signInUrl();
    [/var/www/public/forum/library/vendors/SmartyPlugins/function.signinout_link.php:20] Gdn_Theme::link();
    [/var/www/public/forum/cache/Smarty/compile/vanilla^%%A9^A94^A948A472%%default.master.tpl.php:37] PHP::smarty_function_signinout_link();
    [/var/www/public/forum/library/vendors/smarty/libs/Smarty.class.php:1257] PHP::include();
    [/var/www/public/forum/library/vendors/smarty/libs/Smarty.class.php:1107] Smarty->fetch();
    [/var/www/public/forum/library/core/class.smarty.php:138] Smarty->display();
    [/var/www/public/forum/library/core/class.controller.php:1855] Gdn_Smarty->render();
    [/var/www/public/forum/library/core/class.controller.php:1314] Gdn_Controller->renderMaster();
    [/var/www/public/forum/library/core/class.pluggable.php:199] Gdn_Controller->xRender();
    [/var/www/public/forum/applications/dashboard/controllers/class.homecontroller.php:93] Gdn_Pluggable->__call();
    [/var/www/public/forum/library/core/class.dispatcher.php:326] HomeController->fileNotFound();
    [/var/www/public/forum/index.php:44] Gdn_Dispatcher->dispatch();

    Additional information for support personnel:
    Application: Vanilla
    Application Version: 2.3.1
    PHP Version: 7.1.12-3+ubuntu14.04.1+deb.sury.org+1
    Operating System: Linux
    Server Software: nginx/1.12.1
    User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
    Request Uri: /forum/dashboard/setup
    Controller: Gdn_Database
    Method: Connection
    

    I'm still not entirely sure what the issue is. PDO is installed and works, so I don't think it's that

  • Please ensure all database settings are correct and that you choose "localhost" for your db server

  • MinnitMinnit New
    edited December 2017

    This is the first time I'm setting up the forum

    I created a database for it and set up the DB credentials, but it gives this error:
    Table 'forum.GDN_UserAuthenticationProvider' doesn't exist

    I thought that /dashboard/setup would create the required tables, but it just returns that error.

    What page do I need to go to to create the tables?

  • You never told what screens you already have seen when errors arise. If this is a clean installation, make sure it really looks clean for Vanilla too

    a) delete all tables form that database
    b) delete /conf/config.php
    c) delete all *.ini files in /cache

  • I got it working with the newer 2.5 version of Vanilla.

    Thanks for helping!

Sign In or Register to comment.