Suggested NginX vhost conf

If you're running a NginX webserver you will need a vhost that looks like this.

Code:
location /xf/ {
    try_files $uri $uri/ /xf/index.php?$uri&$args;
    index index.php index.html;
}
 
location /xf/internal_data/ {
    internal;
}
location /xf/library/ {
      internal;
}
 
location ~ \.php$ {
    try_files $uri /xf/index.php =404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

Change /xf paths as required.
 
I have a similar setup, mine's just a bit different, for instance, for whatever reason, $document_root isn't set (so I manually set it).
Code:
  location ~ /\.ht {
    deny  all;
  }
 
  location /community/ {
     root   /something/something/community;
     index  index.php index.html;
     try_files$uri $uri/ /community/index.php?$uri&$args;
  }
 
  location /community/internal_data/ {
    internal;
  }
  
  location /community/library/ {
    internal;
  }
 
  location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME  /something/something/$fastcgi_script_name;
  }
That setup has been working through my xF installation without any problems.

But, for some reason, my games aren't being saved:
Resources
 
Dave,

I believe yours isn't working because you're missing the try_files directive that you can see in my example on line 14. Backup your current installation before attempting the change.

You need to insert

try_files $uri /community/index.php =404;

Let me know how you get on.
 
I've got a wordpress, a custom app, and xF installed on one of my sites, so I can't do something like
Code:
location ~ \.php$ {
    try_files $uri /xf/index.php =404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

as near as I can tell, because I don't want all of the *.php files routed through the xF installation.

My whole setup (for this site anyway), looks something like this:

Code:
#mysite.com main
server {
      listen  123.45.6.7:80;
      server_name .mysite.com;
      # enforce NO www
      if ($host ~* ^www\.(.*))
      {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
      }
      access_log  /blah/public/mysite.com/log/access.log;
      error_log  /blah/public/mysite.com/log/error.log;
 
    gzip  on;
   
    gzip_vary on;
    gzip_comp_level 3;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers 16 8k;
 
    location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|avi|mp3|html)$ {
        expires max;
        log_not_found off;
        access_log off;
        root  /blah/public/mysite.com/;
        error_page 404 /error_pages/404.html;
    }
 
 
    location / {
        root  /blah/public/mysite.com/;
        index  index.html index.htm index.php;
        error_page 404 /error_pages/404.html;
    }
 
    #wordpress
    location /wp/ {
        root  /blah/public/mysite.com/;
        index  index.html index.php;
 
        try_files $uri $uri/ /wp/index.php;
    }
 
    #inventory
    location /inv {
        root  /blah/public/mysite.com/inv;
        index  index.php index.html index.htm;
       
        try_files $uri $uri/ /inv/index.php;
    }
 
    #xf
    location /community/ {
      root  /blah/public/mysite.com/community;
      index  index.html index.htm index.php;
      try_files      $uri $uri/ /community/index.php?$uri&$args;
    }
 
    #get out
    location /community/internal_data/ {
      root  /blah/public/mysite.com/community;
      internal;
    }
   
    #get out
    location /community/library/ {
      root  /blah/public/mysite.com/community;
      internal;
    }
   
    #needed for xfarcade?
    location /community/data/ {
      root  /blah/public/mysite.com/community;
      internal;
    }
 
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /blah/public/mysite.com/$fastcgi_script_name;
    }
                 
    location ~ /\.ht {
                deny  all;
    }
         
}

I've been told that I don't need a lot of stuff in this (like the root directives), but something always seems to break as soon as I start listening to people. :smiley:
 
I tried your suggestion of just adding the try_files in the php block such as:
Code:
    location ~ \.php$ {
        try_files $uri /community/index.php =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /blah/public/mysite.com/$fastcgi_script_name;
    }

But my entire Xf installation returns a Not Found when I implement that.
 
I use php-fpm/nginx and virtual domains for better control of nginx resources

Install Nginx/PHP-FPM on Fedora 29/28, CentOS/RHEL 7.5/6.10 – If Not True Then False
wiki.nginx.org Managed WordPress Site – Just another WordPress site

nginx.conf - stuff I want done on a server wide basis
Code:
user nginx;
# root@server:  cat /proc/cpuinfo |grep processor
# 4 server CPU's =
worker_processes  4;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
pid        /var/run/nginx.pid;
#pid        logs/nginx.pid;
 
    events {
    worker_connections  1024;
    }
    http {
    include      mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush    on;
    # Hide nginx version number from 404 pages etc (server tokens)
    server_tokens off;
    access_log off;
    client_body_buffer_size 8K;
    client_header_buffer_size 1k;
    client_max_body_size 200m;
    large_client_header_buffers 2 1k;
 
    client_body_timeout  10;
    client_header_timeout 10;
    keepalive_timeout    15;
    send_timeout          10;
 
    gzip  on;
    #gzip_static on;
    gzip_comp_level 6;
    gzip_min_length 1100;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain application/xml;
    gzip_disable "MSIE [1-6]\.";
    gzip_types text/plain text/css image/png image/gif image/jpeg application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_http_version 1.1;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
 
    # Set a vary header so downstream proxies don't send cached gzipped content to I$
    gzip_vary on;
    ## /Compression
 
    #POOLS OPEN
    include /etc/nginx/conf.d/*.conf;
 
    #Virtual hosting magic enabled!
     include /etc/nginx/sites-enabled/*;
 
        # do some error pages
          server {
          listen      80;
          server_name  localhost;
          #charset koi8-r;
          #access_log  logs/host.access.log  main;
 
          location / {
          root  html;
          index  index.html index.htm;
          }
 
          #error_page  404              /404.html;
          # redirect server error pages to the static page /50x.html
          #
          error_page  500 502 503 504  /50x.html;
          location = /50x.html {
          root  html;
        }
      }
}

server_name * is a wildcard, anyway

/etc/nginx/sites-enabled/forum.org - just controls the forum domain
Code:
# www. removed from any incoming, links just use htpp://
server {
    server_name  www.forum.org;
    rewrite ^(.*) http://forum.org$1 permanent;
}
# end www. removals
 
server {
    server_name *.forum.org;
    access_log /srv/www/forum.org/logs/access.log;
    error_log /srv/www/forum.org/logs/error.log;
    root /srv/www/forum.org/public_html/forum;
 
#root & rewrites
    location / {
            root /srv/www/forum.org/public_html/forum;
            try_files $uri $uri/ /index.php?$uri&$args;
            index index.html index.htm index.php;
    }
 
    #protect
      location ~ ^/community/(internal_data|library)/(.*)$ { internal;
      }
 
        #I want images etc to expire in 2013 - cue expire headers
        location ~* "\.(js|ico|gif|jpg|png|css|html|htm|swf|htc|xml|bmp|cur)$" {
        root /srv/www/forum.org/public_html/forum;
        expires 1y;
        access_log  off;
        log_not_found off;
        }
 
        location /favicon.ico {
        expires max;
        }
 
      # use fastcgi for all php files
        location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/forum.org/public_html/forum$fastcgi_script_name;
        include fastcgi_params;
      }
 
    # deny access to apache .htaccess files
    location ~ /\.ht
    {
        deny all;
    }
}
 
I've got a wordpress, a custom app, and xF installed on one of my sites, so I can't do something like
Code:
location ~ \.php$ {
    try_files $uri /xf/index.php =404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

as near as I can tell, because I don't want all of the *.php files routed through the xF installation.
#1 virtual hosts (see nginx.conf above) break your sites into separate server/location configs. I do this with xenforo, wordpress etc.
#2: also use Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks – If Not True Then False
and How To Optimize Nginx For Maximum Performance - lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks
With PHP-FPM it’s possible to use different pools for different sites and allocate resources very accurately and even use different users and groups for every pool. Following is just example configuration files structure for PHP-FPM pools for three different sites (or actually three different part of same site):
/etc/php-fpm.d/site.conf
/etc/php-fpm.d/blog.conf
/etc/php-fpm.d/forums.conf

;)
 
D.O.A. on your own forum, what happens if you go to the following urls

http://example.com/acade.php
http://example.com/members.php

These are assuming XenForo is in the root public folder, change the paths as required.

Only reason I ask is because if you're using the vhost as outlined on the NginX wiki then your forum won't be working they way it should.

what the f**k... is this a xenforo problem or nginx? ... felgercarb well I guess I can redirect requests for those files to the right places but that would be pretty messy... what's your solution, if any.
Has this been posted to the nginx mail list? perhaps the hive mind there can be of help....
 
what the f**k... is this a xenforo problem or nginx? ... felgercarb well I guess I can redirect requests for those files to the right places but that would be pretty messy... what's your solution, if any.
Has this been posted to the nginx mail list? perhaps the hive mind there can be of help....
The basic premise of the vhost is in the first post of this thread, you should use that as a base for any xf install. Things become complicated though when you have multiple applications installed on the same domain. The short answer is that I don't have a neat solution for you.

I could share with you what we've managed to get working with SneakyDave which behaves correctly 99% of the time.
 
Here's the basics of what is working for SneakyDave, note he's got some extra stuff going on with his set up so you would really need to look at all the paths and make sure they're applicable to you.

Code:
server {
    listen            xxx.xxx.xxx.xxx:80;
    server_name        www.example.com;
    rewrite ^          http://example.com$request_uri? permanent;
}
 
server {
    listen            xxx.xxx.xxx.xxx:80;
    server_name        example.com;
    access_log        /home/folder/public_html/example.com/log/access.log;
    error_log          /home/folder/public_html/example.com/log/error.log;
    root              /home/folder/public_html/example.com/public;
    index              index.php index.html;
 
    #WP
    location / {
        index  index.html index.htm index.php;
        error_page 404 /page_errors/404.html;
    }
 
 
    location /wp/ {
        index  index.html index.php;
        try_files $uri $uri/ /wp/index.php;
    }
 
    #XF
    location ^~ /community/ {
        root /home/folder/public_html/example.com/public;
     
    location /community/ {
        index  index.html index.htm index.php;
        try_files      $uri $uri/ /community/index.php?$uri&$args;
    }
 
    #Get out
    location /community/internal_data/ {
        internal;
    }
 
    #Get out
    location /community/library/ {
        internal;
    }
 
    #PHP for XF
    location ~ \.php$ {
        #Needed for XF
        try_files $uri /community/index.php =404;
        #try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  /home/folder/public_html/example.com/public$fastcgi_script_name;
    }     
    }
 
    #PHP for everything else
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/folder/public_html/example.com/public$fastcgi_script_name;
    }
}
 
I am having the same issue where no scores are saving on any games.
I have tried these methods and not had any success.
Is there anyone willing to take a look at my Vhost file for me and see if they can figure out the issue.
I am new to nginx so I expect it is only something simple that I can't figure out.
If anyone is willing to help me out, please send me a msg.

Thanks very much
 
Are you sure it's a nginx problem? Do you have Xenporta installed? I'll gladly take a look...but lets start with a simple URL and rule out the obvious issues first.
 
Back
Top