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.

Vanilla on Nginx

I'm trying to install Vanilla 2 on Nginx but am facing 404 Page not found error. After some searching I figured it is url rewrite error. So, tried to translate Apache's rewrite rule:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

as:
if (!-e $request_filename
{
rewrite ^(.*)$ index.php?q=$1 last;
}

But obviously I'm doing something wrong.

Can you help me, please.
«1

Comments

  • edited October 2009
    This configuration did not work for me. So I did some more research into this and found something better and more targetted towards the path_info fcgi fix. Keep in mind the previous configure might be for Lighttpd spawn-fcgi. I'm currently using nginx with php5-cgi from the ubuntu repos.

    server {
    listen 80;
    server_name sub.domain.com;

    access_log /home/name/sub.domain.com/logs/access.log;
    error_log /home/name/sub.domain.com/logs/error.log;

    location / {
    root /home/name/sub.domain.com/public;
    index index.php;

    if (-f $request_filename) {
    break;
    }

    if (-d $request_filename) {
    break;
    }

    rewrite ^(.+)$ /index.php$1 last;
    error_page 404 = /index.php;
    }

    location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/name/sub.domain.com/public$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    }

    #
    # path_info fix
    #

    location ~ \.php($|/) {

    set $script $uri;
    set $path_info "";

    if ($uri ~ "^(.+\.php)(/.+)") {
    set $script $1;
    set $path_info $2;
    }

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/name/sub.domain.com/public$script;
    fastcgi_param SCRIPT_NAME $script;
    fastcgi_param PATH_INFO $path_info;

    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 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;

    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 $server_name;
    fastcgi_param REDIRECT_STATUS 200;

    }
    }
    This is direct from my configuration. The previous was giving me incomplete url errors server-side. Tried to take a look at the rewrite rules. Everything checked out other than /index.php/ location. This method was causing failure in my setup on my cloud configuration.
  • I will possibly look into getting everything working correctly under Cherokee also.
  • None of these setups seem to work for a Vanilla2 setup under a sub directory. It seems like the cgi.fix_pathinfo setting in php.ini affects this quite abit.
  • This is half working for me under a sub-directory. But all of my links look like:

    /forum/index.php/garden/gardensetup

    How do I get rid of /index.php/ on everything?

  • @houseofmore in your config.php, adjust the following to be True: $Configuration['Garden']['RewriteUrls'] = TRUE;
  • eleitheleith New
    edited March 2010
    here is a less verbose nginx site conf i've got working for me:

    server {
    listen 80;
    server_name sub.domain.com;

    root /path/to/garden;
    index index.php index.html;

    location / {
    if (-f $request_filename) {
    break;
    }
    if (-d $request_filename) {
    break;
    }
    rewrite ^(.+)$ /index.php$1 last;
    }

    location ~ \.php($|/) {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;

    set $script $uri;
    set $path_info "";

    if ($uri ~ "^(.+\.php)(/.+)") {
    set $script $1;
    set $path_info $2;
    }

    fastcgi_param SCRIPT_FILENAME $document_root$script;
    fastcgi_param SCRIPT_NAME $script;
    fastcgi_param PATH_INFO $path_info;
    }
    }
  • Yep .. I can confirm that the above works for me.
    Thanks, people!
  • I was unable to get rewrites working with nginx with vanilla outside of the forum root. I gave up on trying to do it all in nginx, and added this to the top of the index.php in vanilla.

    $_SERVER['PATH_INFO'] = preg_replace('|^/forum|','', $_SERVER['REQUEST_URI']);

    /forum being my root. In nginx, all I have is:

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

    Seems to work fine: http://www.checkfront.com/forum/

    Cheers,
    -J
  • Hi there!

    I must be a total newbie at this. But Im getting the same error "No Input file Specified"

    - I cant find the config.php file. There seems to not be a config.php file in Vanilla 2 RC1. But I do see a config-default.php in the config folder.

    2. I do not know if all these fixes listed above applies to me since I have godaddy deluxe hosting which is linux. Anyone know where kind this is?

    3. Ive actually cmodded my whole directories and subfolders/files with 777. Yes I know this is very insecure, but I wanted to see if this would solve the problem and thats a Negative.

    Id really appreciate some help for the php not inclined person. Id like a step by step guide on how to do this just like a little child if possible.

    Thanks for all you do!
  • lucluc ✭✭
    1. config.php is created during setup.
  • Ehhh? Ive never even got to setup. Sorry. Thanks for the quick answer!

    However, When i point my browser to the install folder, in this case "Forum", I get the error "No input File Specified"

    Further details is, I point it to the folder like this: http://forum.xxxxxxxx.com/forum
    and I get this: www.forum.xxxxxxx.com/forum/index.php/dashboard/setup

    Again any help would be appreciated.

    -Tim

  • TimTim Operations Vanilla Staff
    Can you show me your config file, becool?

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • None of these configurations work properly with rewriting routes. I currently have my configuration as http://gist.github.com/564341 Unfortunately, all of my Vanilla 1.x routes have stopped working, so all Google search results are f'ed.
  • Tried everything above, but having a little trouble with nginx and rewriteurls.

    location /forums { try_files $uri $uri/ /forums/index.php?$uri; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; include fastcgi_params; fastcgi_intercept_errors on; }

    path info is empty
    if I add: fastcgi_param PATH_INFO $request_uri;
    then path info is /forums/post/discussion

    every page is the index page
  • I'm trying to debug this. I don't know what the server values should be. I have an installation domain.com/forums/, and using rewrite urls = true.

    I'm using this url in the browser to test each change, until I see something that looks right. domain.com/forums/post/discussion

    _SERVER["QUERY_STRING"] no value
    _SERVER["SCRIPT_NAME"] /forums/post/discussion
    _SERVER["SCRIPT_FILENAME"] /var/www/domain.com/forums/index.php
    _SERVER["REQUEST_URI"] /forums/post/discussion
    _SERVER["DOCUMENT_URI"] /forums/post/discussion
    _SERVER["DOCUMENT_ROOT"] /var/www/domain.com
    _SERVER["PATH_INFO"] no value
    _SERVER["PATH_TRANSLATED"] /var/www/domain.com
    _SERVER["PHP_SELF"] /forums/post/discussion

    If I visit /forums/post/discussion in the browser, I'm currently seeing the default front page, but the paths to the css, js, etc.. are all incorrect and looking for the paths to these files from the document root instead of from /forums where my install is.

    I hope this helps a bit more in diagnosing my issue.
  • I have this working for me, for now with the following:

    location /forums { if (!-e $request_filename) { rewrite ^/forums(.+)$ /forums/index.php?p=$1 last; } }

    The server variables are:
    script_filename => /var/www/domain.com/forums/index.php
    script_name => /forums/index.php
    query_string => p=/post/discussion
    request_uri => /forums/post/discussion
    path_info =>
    path_translated => /var/www/domain.com
    php_self => /forums/index.php

  • Here's the way I was able to tackle nginx w/ Vanilla:
    location /forum {try_files $uri $uri/ @forum;}
    location @forum {rewrite ^/forum(.+)$ /forum/index.php?p=$1 last;}
    It's better not to use if statements ( http://wiki.nginx.org/IfIsEvil ), and the @ syntax provides for named locations, which is useful for having systems not in the root path, etc. Short and sweet.
  • lucluc ✭✭
    try_files is indeed the new thing to use, as far as I can tell reading new stuff on nginx. It wasn't there at first though, that's why they are still many examples with "if".
Sign In or Register to comment.