NGINX Friendly URL Rewrite?

KeVo

Active member
Hello,

I am using Centmin mod on my VPS and I am getting this weird error when I attempt to restart NGINX.

nginx: [emerg] "location" directive is not allowed here in /usr/local/nginx/conf/staticfiles.conf:1
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

I get this after what I assume is me putting the rewrite into my file. Any idea(s) on what may be causing this?
 
I get this after what I assume is me putting the rewrite into my file. Any idea(s) on what may be causing this?
@Floren will step in shortly and tell you to quit using what you find via Google and go to the nginx wiki to research the correct way to do it, <RD&G as fast as my legs will carry me now>

And actually, he's 100% correct. You cannot trust 98% of what you find via google unless it is via the official nginx support site/wiki. Without seeing your "staticfiles.conf" it's kind of hard to say. You are basically trying to place a location in the incorrect position of your definition.
I'm assuming you've used nginx in the past and are already familiar with it?
 
Have you changed your staticfiles.conf file in any way?

We need to see what you have changed in that file, and how you are trying to include that in your server block for the specific site.
 
@Floren will step in shortly and tell you to quit using what you find via Google and go to the nginx wiki to research the correct way to do it
Heh :giggle:
I'm not familiar with CentminMod and its configuration files. Regardless, the error is self explanatory.
Personally, I will never encourage someone to run a shell script that compiles locally a bunch of tarballs, with a chance to create chaos on your server...
 
But ordered chaos is good :D Most likely the problem is end user modified changes and NOT specific to Centmin Mod itself. I and many folks have no problems with Centmin Mod :)

@Shooting Scarz which files did you edit for your rewrite rule ? To troubleshoot you should always document your changes as you proceed. That way you can revert changes to test for bugs in your configuration and steps. Try reverting your changes one at a time and see which allows you to properly restart Nginx.

FYI, rewrite rules should go in your domain's Nginx vhost config file at /usr/local/nginx/conf/conf.d/yourdomain.com.conf
 
But ordered chaos is good :D Most likely the problem is end user modified changes and NOT specific to Centmin Mod itself. I and many folks have no problems with Centmin Mod :)

@Shooting Scarz which files did you edit for your rewrite rule ? To troubleshoot you should always document your changes as you proceed. That way you can revert changes to test for bugs in your configuration and steps. Try reverting your changes one at a time and see which allows you to properly restart Nginx.

FYI, rewrite rules should go in your domain's Nginx vhost config file at /usr/local/nginx/conf/conf.d/yourdomain.com.conf

I may not be adding the information in the correct area, as written by the shell's maker. But, here is what I have written in that particular file /usr/local/nginx/conf/conf.d/yourdomain.com.conf.

Code:
server {
  server_name MYDOMAIN.com www.MYDOMAIN.com;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/MYDOMAIN.com/log/access.log combined buffer=32k;
  error_log /home/nginx/domains/MYDOMAIN.com/log/error.log;

  root /home/nginx/domains/MYDOMAIN.com/public;

  location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$uri&$args;
       
        }

        location /internal_data/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

        location /library/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;

  # Enables directory listings when index file not found
  #autoindex  on;

  # Shows file listing times as local time
  #autoindex_localtime on;

  # Enable for vBulletin usage WITHOUT vbSEO installed
  #try_files        / /index.php;

  }

  include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
}

Now, I should state this is my first rodeo with nginx or being without a panel period. I tried following this guide here: http://centminmod.com/nginx_configure_xenforo_seo_friendly_urls.html

I can also confirm that I can restart nginx properly, problem free prior to this edit.

Here is the file before being altered:

Code:
server {
  server_name MYDOMAIN.com www.MYDOMAIN.com;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/MYDOMAIN.com/log/access.log combined buffer=32k;
  error_log /home/nginx/domains/MYDOMAIN.com/log/error.log;

  root /home/nginx/domains/MYDOMAIN.com/public;

  location / {

# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;

  # Enables directory listings when index file not found
  #autoindex  on;

  # Shows file listing times as local time
  #autoindex_localtime on;

  # Enable for vBulletin usage WITHOUT vbSEO installed
  #try_files         / /index.php;

  }

  include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
}
 
Last edited:
I and many folks have no problems with Centmin Mod :)
The fact the product is just a shell script, for me says it all. How do you revert back to stock, if you need to? I'm not sure if the script has an uninstall step. Yum (or other Linux alternatives) is is the ONLY proper way to install software on your server, period. Here it is an example, where is OPCache (built in PHP 5.5.x)? I only see APC and XCache available... Not to mention that if you want to secure your site against Heartbleed, you have to rebuild everything as the software was originally compiled against a vulnerable version. Unless I'm mistaken and the script compiles everything against default OS libraries.

I'm almost done with my site revamp, finalizing the last bits of code... then I will post a tutorial how to set your server in less than 5 minutes for XenForo, securely and easily reversible. That is the power of Yellow Dog Updater.
 
I'm almost done with my site revamp, finalizing the last bits of code... then I will post a tutorial how to set your server in less than 5 minutes for XenForo, securely and easily reversible. That is the power of Yellow Dog Updater.

I would very much like to see your tutorial when it's finished. :)
 
I may not be adding the information in the correct area, as written by the shell's maker.
That configuration is pretty confusing for myself, imagine for an inexperienced user. It does not shows any settings, just a bunch of includes, ridiculous. Is not your fault, is just a bad configuration logic. Take a look at this basic tutorial, to help you understand the configuration flow in Nginx:
https://www.axivo.com/resources/basic-configuration.3/
 
The fact the product is just a shell script, for me says it all. How do you revert back to stock, if you need to? I'm not sure if the script has an uninstall step. Yum (or other Linux alternatives) is is the ONLY proper way to install software on your server, period. Here it is an example, where is OPCache (built in PHP 5.5.x)? I only see APC and XCache available... Not to mention that if you want to secure your site against Heartbleed, you have to rebuild everything as the software was originally compiled against a vulnerable version. Unless I'm mistaken and the script compiles everything against default OS libraries.

I'm almost done with my site revamp, finalizing the last bits of code... then I will post a tutorial how to set your server in less than 5 minutes for XenForo, securely and easily reversible. That is the power of Yellow Dog Updater.

  • For existing Centmin Mod users and OpenSSL just need to edit centmin.sh change OPENSSL_VERSION variable to 1.0.1g and run menu option #4 to recompile Nginx https://plus.google.com/104831941868856035845/posts/UB8nZn4ceNp. For new users, .06 stable and .07 beta default to OpenSSL 1.0.1g for Nginx.
  • Centmin Mod .07 next release (currently in beta) has Zend OpCache added to menu #12 option https://blog.centminmod.com/327 as well as option for out of box OpCache. I'm playing with beta and install time for my VPS is around 1100 seconds
.07 release can now also allow users to override the default installed PHP Opcode cacher – APC Cache with Zend OpCache by editing centmin.sh and changing ZOPCACHEDFT=’n’ to ZOPCACHEDFT=’y’ prior to initial install or after install (for PHP upgrades).

That configuration is pretty confusing for myself, imagine for an inexperienced user. It does not shows any settings, just a bunch of includes, ridiculous. Is not your fault, is just a bad configuration logic. Take a look at this basic tutorial, to help you understand the configuration flow in Nginx:
https://www.axivo.com/resources/basic-configuration.3/

Confusion = absence of experience. That can be said for anything new or foreign to anyone :)
 
Last edited:
I may not be adding the information in the correct area, as written by the shell's maker. But, here is what I have written in that particular file /usr/local/nginx/conf/conf.d/yourdomain.com.conf.

Code:
server {
  server_name MYDOMAIN.com www.MYDOMAIN.com;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/MYDOMAIN.com/log/access.log combined buffer=32k;
  error_log /home/nginx/domains/MYDOMAIN.com/log/error.log;

  root /home/nginx/domains/MYDOMAIN.com/public;

  location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$uri&$args;
     
        }

        location /internal_data/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

        location /library/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;

  # Enables directory listings when index file not found
  #autoindex  on;

  # Shows file listing times as local time
  #autoindex_localtime on;

  # Enable for vBulletin usage WITHOUT vbSEO installed
  #try_files        / /index.php;

  }

  include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
}

Now, I should state this is my first rodeo with nginx or being without a panel period. I tried following this guide here: http://centminmod.com/nginx_configure_xenforo_seo_friendly_urls.html

I can also confirm that I can restart nginx properly, problem free prior to this edit.

Here is the file before being altered:

Code:
server {
  server_name MYDOMAIN.com www.MYDOMAIN.com;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/MYDOMAIN.com/log/access.log combined buffer=32k;
  error_log /home/nginx/domains/MYDOMAIN.com/log/error.log;

  root /home/nginx/domains/MYDOMAIN.com/public;

  location / {

# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;

  # Enables directory listings when index file not found
  #autoindex  on;

  # Shows file listing times as local time
  #autoindex_localtime on;

  # Enable for vBulletin usage WITHOUT vbSEO installed
  #try_files         / /index.php;

  }

  include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
}

either do one of 2 things in your existing problematic vhost file

1. remove line 23 close curly bracket } or
2. remove line 23 close curly bracket + move lines 23 to 33 to around line 48
 
Last edited:
I'm almost done with my site revamp, finalizing the last bits of code... then I will post a tutorial how to set your server in less than 5 minutes for XenForo, securely and easily reversible. That is the power of Yellow Dog Updater.
Nothing against YUM but nothing against source compiles either :) Wouldn't mind giving your method a try for 100% YUM install see how long it takes to install the following feature set below purely from YUM

  • Nginx 1.5.13 + ngx_pagespeed module
  • PHP-FPM 5.4.27
  • APC Cache or Xcache or Zend Opcache
  • MariaDB 5.5.36
  • Memcached 1.4.17
  • NSD
  • NTPD
  • Python 2.6 or .2.7
  • GIT
  • CSF Firewall + SPROXY and time to configure for all needed ports and services

and the following PHP extensions

  • bcmath
  • bz2
  • calendar
  • Core
  • ctype
  • curl
  • date
  • dom
  • ereg
  • exif
  • fileinfo
  • filter
  • ftp
  • gd
  • gettext
  • hash
  • iconv
  • igbinary
  • imagick
  • imap
  • intl
  • json
  • ldap
  • libxml
  • mbstring
  • mcrypt
  • memcache
  • memcached
  • mhash
  • mysql
  • mysqli
  • mysqlnd
  • openssl
  • pcntl
  • pcre
  • PDO
  • pdo_mysql
  • pdo_sqlite
  • Phar
  • posix
  • readline
  • Reflection
  • session
  • shmop
  • SimpleXML
  • soap
  • sockets
  • SPL
  • sqlite3
  • standard
  • sysvmsg
  • sysvsem
  • sysvshm
  • tokenizer
  • xml
  • xmlreader
  • xmlrpc
  • xmlwriter
  • zip
  • zlib
Code:
time yum -y install package(s)
 
Strange then.. i wouldn't stop trying to resolve the issue as there's a reason some of the include files are there.

try just commenting out staticfiles.conf and see

Code:
server {
  server_name MYDOMAIN.com www.MYDOMAIN.com;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/MYDOMAIN.com/log/access.log combined buffer=32k;
  error_log /home/nginx/domains/MYDOMAIN.com/log/error.log;

  root /home/nginx/domains/MYDOMAIN.com/public;

        location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$uri&$args;
       
        }
        location /internal_data/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

        location /library/ {
        internal;
        allow 127.0.0.1;
        deny all;
        }

# include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
}
 
Nothing against YUM but nothing against source compiles either :) Wouldn't mind giving your method a try for 100% YUM install see how long it takes to install the following feature set below purely from YUM
Code:
time yum -y install package(s)
  • Nginx 1.5.13 + ngx_pagespeed module
  • PHP-FPM 5.4.27 5.5.11
  • APC Cache or Xcache or Zend Opcache 5.5.11
  • MariaDB 5.5.36
  • Memcached 1.4.17
  • NSD 4.0.3 (about to release it)
  • NTPD (stock Red Hat)
  • Python 2.6.6 or .2.7 (stock Red Hat)
  • GIT (stock Red Hat)
  • CSF Firewall + SPROXY Selinux rulez
Should take you 3 minute to install all that... depending on your speed.
And PHP.... only the useful extensions are deployed, some which you miss on your list and some that are included into php-common. Of course, everything is compiled against OpenSSL 1.0.1g, the same day they release it. :)
Code:
$ yum --disablerepo=* --enablerepo=axivo list php*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
php-cli.x86_64                          5.5.11-1.el6           @axivo
php-common.x86_64                       5.5.11-1.el6           @axivo
php-devel.x86_64                        5.5.11-1.el6           @axivo
php-fpm.x86_64                          5.5.11-1.el6           @axivo
php-gd.x86_64                           5.5.11-1.el6           @axivo
php-mbstring.x86_64                     5.5.11-1.el6           @axivo
php-mysqlnd.x86_64                      5.5.11-1.el6           @axivo
php-opcache.x86_64                      5.5.11-1.el6           @axivo
php-pdo.x86_64                          5.5.11-1.el6           @axivo
php-pear.noarch                         2:1.9.4-1.el6          @axivo
php-pecl-geoip.x86_64                   1.0.8-1.el6            @axivo
php-pecl-http.x86_64                    2.0.3-1.el6            @axivo
php-pecl-igbinary.x86_64                1.1.1-1.el6            @axivo
php-pecl-igbinary-devel.x86_64          1.1.1-1.el6            @axivo
php-pecl-imagick.x86_64                 3.1.2-1.el6            @axivo
php-pecl-jsonc.x86_64                   1.3.3-1.el6            @axivo
php-pecl-jsonc-devel.x86_64             1.3.3-1.el6            @axivo
php-pecl-memcached.x86_64               2.1.0-1.el6            @axivo
php-pecl-propro.x86_64                  1.0.0-1.el6            @axivo
php-pecl-raphf.x86_64                   1.0.4-1.el6            @axivo
php-xml.x86_64                          5.5.11-1.el6           @axivo
Available Packages
php.x86_64                              5.5.11-1.el6           axivo
php-bcmath.x86_64                       5.5.11-1.el6           axivo
php-dba.x86_64                          5.5.11-1.el6           axivo
php-embedded.x86_64                     5.5.11-1.el6           axivo
php-enchant.x86_64                      5.5.11-1.el6           axivo
php-gmp.x86_64                          5.5.11-1.el6           axivo
php-imap.x86_64                         5.5.11-1.el6           axivo
php-intl.x86_64                         5.5.11-1.el6           axivo
php-ldap.x86_64                         5.5.11-1.el6           axivo
php-mcrypt.x86_64                       5.5.11-1.el6           axivo
php-mssql.x86_64                        5.5.11-1.el6           axivo
php-odbc.x86_64                         5.5.11-1.el6           axivo
php-pecl-http-devel.x86_64              2.0.3-1.el6            axivo
php-pecl-imagick-devel.x86_64           3.1.2-1.el6            axivo
php-pecl-propro-devel.x86_64            1.0.0-1.el6            axivo
php-pecl-raphf-devel.x86_64             1.0.4-1.el6            axivo
php-pgsql.x86_64                        5.5.11-1.el6           axivo
php-process.x86_64                      5.5.11-1.el6           axivo
php-pspell.x86_64                       5.5.11-1.el6           axivo
php-recode.x86_64                       5.5.11-1.el6           axivo
php-snmp.x86_64                         5.5.11-1.el6           axivo
php-soap.x86_64                         5.5.11-1.el6           axivo
php-tidy.x86_64                         5.5.11-1.el6           axivo
php-xmlrpc.x86_64                       5.5.11-1.el6           axivo
Code:
$ rpm -q --provides php-common | uniq | sort
bz2.so()(64bit)
calendar.so()(64bit)
config(php-common) = 5.5.11-1.el6
ctype.so()(64bit)
curl.so()(64bit)
exif.so()(64bit)
fileinfo.so()(64bit)
ftp.so()(64bit)
gettext.so()(64bit)
iconv.so()(64bit)
openssl.so()(64bit)
pcntl.so()(64bit)
phar.so()(64bit)
php-api = 20121113
php(api) = 20121113
php-bz2
php-calendar
php-common = 5.5.11-1.el6
php-common(x86-64) = 5.5.11-1.el6
php-core = 5.5.11
php-ctype
php-curl
php-date
php-ereg
php-exif
php-fileinfo
php-filter
php-ftp
php-gettext
php-gmp
php-hash
php-iconv
php(language) = 5.5.11
php-libxml
php-mhash
php-openssl
php-pcre
php-phar
php-reflection
php-session
php-sockets
php-spl
php-standard = 5.5.11
php-tokenizer
php-zend-abi = 20121212
php(zend-abi) = 20121212
php-zip
php-zlib
sockets.so()(64bit)
tokenizer.so()(64bit)
zip.so()(64bit)
zlib.so()(64bit)
I dare you to do the same thing with Centminmod. :giggle:
 
Last edited:
Well tried
  • YUM total time= 9 1/2 mins
  • Centmin Mod with with following disabled ngx_pagespeed module, CSF/SPROXY = 14 1/2 mins
Guess you live in a much faster net connected world than most. But yes we all expect YUM to be faster but difference ain't much in time.
 
Well tried
I did not know Centminmod has all the packages you listed above, is it accurate?
Guess you live in a much faster net connected world than most. But yes we all expect YUM to be faster but difference ain't much in time.
I don't, is the normal speed I get on OVH network. And is not about the time spent, is about how easy you can ruin your server by running a shell script. Can you perform an uninstall on Centminmod? In Red Hat, all I have to do is:
# yum history undo XX
It will revert back to the previous state my system was.
Don't get me wrong, I'm not trying to put down the work done by George, not to mention he is a great guy. I'm just saying that scripting has its place and setting up web services with it is not one of them. At least in my books. I use a lot of shell scripting to automate repetitive tasks, one of them being XenForo CLI upgrade.

OK, I promise I will comment anymore on that aspect as is not fair, not to mention that I hijacked the thread. :giggle:
Thank you for listening to my "personal" opinions.
 
Last edited:
I did not know Centminmod has all the packages you listed above, is it accurate?

Centmin mod includes several packages as default and several others as options. By default Nginx alone has the following options:
  • --with-http_ssl_module
  • --with-http_gzip_static_module
  • --with-http_stub_status_module
  • --with-http_sub_module
  • --with-http_addition_module
  • --with-http_secure_link_module
  • --with-http_flv_module
  • --with-http_realip_module
  • ngx-fancyindex
  • ngx_cache_purge
  • nginx-accesskey
  • --with-http_dav_module
  • nginx-dav-ext-module
  • nginx-http-concat
  • Google ngx_pagspeed module
  • Nginx SPDY module
It also includes CSF, memcached, Siege, ioping, mariaDb and more.

I've used it in the past when I just wanted to get a web server running quickly. I prefer setting everything up manually though.
 
Top Bottom