Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 12

ericgillettelucmcu_hq +9 guests

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.

Comments

  • Posts: 4,883
    Kamran eventually figured out this nginx problem and emailed it to me:
    Vanilla installation bug on Nginx was bugging me.... so tonight I spent sometime to figure out what was wrong. As it appeared, Nginx doesn't pass path_info variable to FastCGI, which is required to support vanilla's URL format.

    Once, I figured out the issue, fix was pretty simple i.e. directly point SCRIPT_FILE variable to index.php, instead of traditional /. So, in most basic format, here is how the config file should look like:
    server {

    listen 80;
    server_name sub.domain.com;

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

    location /index.php/ {

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


    location / {

    root /home/name/public_html/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;
    }
    }
    Hope that will be helpful for you in the future. Now I've to figure out how to enable pretty links. I believe there is a setting in config-default.php, correct?
  • Posts: 4
    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.
  • Posts: 4
    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?

  • Posts: 83
    @houseofmore in your config.php, adjust the following to be True: $Configuration['Garden']['RewriteUrls'] = TRUE;
  • Posts: 83
    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
  • Posts: 39
    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
    Posts: 1,015
    1. config.php is created during setup.
  • Posts: 39
    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
    Posts: 1,573
    Can you show me your config file, becool?

    Vanilla Forums Senior Developer [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.
  • Posts: 64
    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
  • Posts: 64
    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.
  • Posts: 64
    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

  • Posts: 8
    Just wanted to thank everyone for their tips and also wanted to inform you all of a solution which actually allows for 'search', post deletions, flagging and others to work.
    Previously with /index.php?p=$uri; one could not get http://domain.tld/search?Search=abc to work due to args not being proxied.
    location / {
    try_files $uri $uri/ /index.php?p=$uri&$args;
    }
    For forums which are in non-root directories, the following should work:
    location /forum/ {
    try_files /forum$uri /forum$uri/ /forum/index.php?p=$uri&$args;
    }
    Also, don't be an idiot like myself and set
    $Configuration['Garden']['RewriteUrls'] = TRUE;
    in conf/config.php instead of wondering why pretty urls aren't working!
  • Posts: 1
    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
    Posts: 1,015
    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".
  • Posts: 64
    Getting emails like this. Is it coming from here?

    [Penny Arcade] Todd commented on your bookmarked discussion.

    Todd commented on your bookmarked discussion.

    [Vanilla on Nginx]
    Test @"Soviet Simplex"

    ---
    Follow the link below to check it out:
    http://vanilla.local/discussion/comment/140660#Comment_140660
  • lucluc
    Posts: 1,015
    @Todd doing test :). I notified him.
    He surely made a copy of the production database, then doing local test.
  • Posts: 1,587
    @brujah, sorry!!! I was testing and edited a random name.

    Vanilla co-founder

  • Posts: 60
    I found that the nginx config setup for MyBB worked with Vanilla out of the box, no modifications required. nginx 1.0.4 on Ubuntu 11.
  • Posts: 14

    dandv said: I found that the nginx config setup for MyBB worked with Vanilla out of the box, no modifications required. nginx 1.0.4 on Ubuntu 11.

    It's not true. Doesn't work at all.

    rlaskey said: 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.

    Links Logout, SignIn, all social connects are broken with 403 Forbidden.

    Please give somebody really working NGINX rewrites for lasted version of Vanilla!!!

  • lucluc
    Posts: 1,015

    @neolo: Did you do that ?:

    swook said:

    Also, don't be an idiot like myself and set

    $Configuration['Garden']['RewriteUrls'] = TRUE;

    in conf/config.php instead of wondering why pretty urls aren't working!

    As this very forum (vf.org) is ran off nginx, it does work for sure :)

  • TimTim
    Posts: 1,573
    server {
    
       server_name "myforum.whatever.com";
       listen 80 default;
    
       root /var/www/myforum;
       index index.html index.htm index.php;
    
       ## PHP handler
       location ~* \.php$ {
          # turn off caching for php
          expires -1;
    
          # send to fastcgi
          include fastcgi_params;
          fastcgi_pass    backend;
       }
    
       ## Default location
       location / {
          try_files $uri @site;
       }
    
       location @site {
          rewrite ^ /index.php?p=$uri&$args last;
       }
    
       ## Disable viewing .htaccess & .htpassword & config
       location ~ "^/\.htaccess$" { deny all; }
       location ~* "/conf/.*$" { deny all; return 403; }
    }
    
    upstream backend {
       server 127.0.0.1:9000;
    }
    

    Vanilla Forums Senior Developer [GitHub, Twitter, About.me]

  • TimTim
    Posts: 1,573

    Vanilla Forums Senior Developer [GitHub, Twitter, About.me]

  • Posts: 14

    Tim said: @Neolo

    Thanks but this piece of config is not working for me:

    location @site { rewrite ^ /index.php?p=$uri&$args last; }

    I'm using embedded vanilla on lasted nginx+php-fpm. And seems to be I forced it to work fine with:

    location /discuss { index index.php; try_files $uri $uri/ @forum; } location @forum { rewrite ^/discuss(.+)$ /discuss/index.php?p=$1 last; }

    Just last time I tried to use this code, I forgot to define an index page.

    Thank you.

Sign In or Register to comment.