Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GS and NGINX
#26
It won't work without altering GS files. However you can use a workaround.
  1. Install the i18n plugin.
  2. Replace every function in your theme with its available i18n counterpart.
  3. Turn on clean URIs.
  4. Put %parents%/%slug%/ in your custom URI scheme.
  5. In your nginx config file put this:
    Code:
    location / {
        rewrite /?([A-Za-z0-9_-]+)/?$ /index.php?id=$1&$2 last;
    }
        
    location /admin {
        try_files    $uri    $uri/    /admin/index.php?id=$uri&$args;
    }
Reply
#27
Maybe one of these days we can get an nice nginx config put on github.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#28
This is a bit complicated. Common practice in inginx is to have a full server configuration along with locations in one single file, contrary to Apache, where it's common to regulate location access per folder with .htaccess files.

A full blown nginx server config template won't be suitable for each and every installation as different projects may require different configuration.

One way around this is to have a locations-only file with the adnotation that it needs to be included in a proper gs server config.

Another way is to have a very basic config template with the adnotation that this config is in fact very basic and needs to be adjusted to work properly.

I need to do a bit more testing and then I'll be able to provide both if needed.
Reply
#29
not yet in the semi-official config, but a few more suggestions for advance setting. All tested and used in production for years:

if using a modern debian server (can't tell about other distros) and knowing what you're doing we can set fastcgi_cache_path /run/shm/ and not /var/cache/ (df should confirm that /run/shm is mounted using tmpfs that defaults to ram).

additional security to admin and login area is quite easy:
# protect login.php and php files in admin/
location ~ (login\.php|admin/.*\.php) {
auth_basic "additional security layer here!";
auth_basic_user_file one-more-pass;
[........]
}

plus we can use stricter rate limiting only for that stanza. I usually have something site-wide like:
#create two zones in order to mitigate small attacks
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server {
limit_conn perip 3;
limit_conn perserver 12;
## Block some robots ##
if ($http_user_agent ~* MJ12bot|scrapbot|bingbot) {
return 403;
}

and since someone asked about preventing hotlinking that's quite easy

location ~ /dont-hotlink/ {
valid_referers www.mysite.com;

(keep in mind that while limiting hotlinlinking you can sometimes want to grant access to google, in order to get more visits, and images must appear in google images search)

lst but not least, everyone interested in nginx advanced config should read http://nginx.com/resources/admin-guide/

and please, PLEASE report in this thread findings, suggestions and ideas to create a even better config.

my idea is to have something good enough to post it to github too. But i'd like someone else help me verify everything in those 2 (basic and advanced) config
Reply
#30
yes, an advanced or secured additional config would be useful
probably for apache also, there is some stuff in wiki for that, enable compression, cache tweaks etc.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#31
I'm trying to set up GS on an nginx server, where GS is not in the root directory of the site but only handles a subdirectory (example.com/publications). Rewrites aren't working as expected.

My nginx config:

Code:
index         index.php index.html;

  location /publications/
  {
    try_files       $uri $uri/ /publications/index.php?id=$uri&$args;
  }

  location ~* /publications/admin/.*\.php$
  {
    try_files       $uri /publications/admin/index.php?id=$uri&$args;
    include         php_params;
  }

  location ~* \.php$
  {
    try_files       $uri =404;
    include         php_params;
  }

The "php_params" file is a shortcut I use that handles all the fastcgi stuff. (I host several other sites, including some Wordpress ones where we've converted the .htaccess to nginx configs, and they all work just fine, so I'm quite sure the "php_params" isn't the issue.)

With the above config, what happens is this:
  • example.com/publications force downloads the GS index.php (i.e. it isn't interpreted by PHP)
  • example.com/publications/ force downloads as well
  • example.com/publications/index.php works and loads the page I set up in GS as the index
  • example.com/publications/test-page loads a GS-formatted 404 page
  • example.com/publications/test-page/ loads a GS-formatted 404 page, except without any CSS files (since the URLs for the stylesheets are now "publications/style.css" instead of "style.css")
  • example.com/publications/index.php?id=test-page works as expected

I have Use Fancy URLs enabled in the General Settings, and the Permalink Structure is "%parent%/%slug%/" (although the input field is disabled and I can't edit it).

Any idea where I messed up?
Reply
#32
Thanks @marrco for posting the nginx config for GS, I used the one from post #9 in this thread, running on a raspberry pi, I wanted a lightweight server for a low traffic site which I am hosting on my ADSL line.
Its all working great and running fast. I am a noob at all this php/web stuff but a long term *nix person and had no troubles getting it all working.
Reply
#33
(2012-02-07, 05:22:30)[/root.] Wrote: I'm using this code

Code:
       location / {
               try_files $uri $uri/ /index.php?id=$uri;
       }

and it works well with the %slug% structure. if I use %parent/%slug% it throws me a 404 error for all child pages.

Any ideas? Thanks.

Hi, I am having the exact same issue, did you ever find a solution?

currently I am using: try_files $uri $uri/ /index.php?id=$uri&$args;

only top level pages are working...

Thanks!
Reply




Users browsing this thread: 2 Guest(s)