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?
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.
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;
}
}
$Configuration['Garden']['RewriteUrls'] = TRUE;
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;
}
}
$_SERVER['PATH_INFO'] = preg_replace('|^/forum|','', $_SERVER['REQUEST_URI']);
location /forum/ {
try_files $uri /forum/$uri/ /forum/index.php?$uri;
}
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;
}
location /forums {
if (!-e $request_filename) {
rewrite ^/forums(.+)$ /forums/index.php?p=$1 last;
}
}
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;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. 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!!!
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;
}
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.
It looks like you're new here. If you want to get involved, click one of these buttons!