LimeSurvey Nginx rewrite rules
I just downloaded LimeSurvey, an amazing free open-source project for creating your own online surveys, and was about to install it on my own Nginx-powered server. To my surprise, there are no available Nginx rewrite rules for it on the official project website, and I didn't even find any blog post detailing such rules. So here I go again, filling the voids.
This post details:
- the Nginx rewrite rules translated directly from the provided .htaccess file, the small server configuration file containing the rewrite rules for Apache.
- what to do after installing LimeSurvey
Nginx rewrite rules
The original rewrite rules for LimeSurvey are contained in this simple .htaccess file:<IfModule mod_rewrite.c>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
# General setting to properly handle LimeSurvey paths
# AcceptPathInfo on
Before you copy the Nginx-compatible rules below, you should ideally try to understand what the above does. The first two lines (IfModule... RewriteEngine on) enable the rewrite rules only if the rewrite module is enabled. Normally it should be the case by default on Nginx so you don't need to worry about that.
The following lines (RewriteCond...) specify conditions for the URL to be rewritten. The first line (!-f) ensures that the requested URI doesn't really exist. For example, if the visitor requests /document.txt and that file actually exists on your server, then the URI doesn't need to be rewritten at all; the file can be served as is. The second line (!-d) does the same for folders; if the requested URI corresponds to an existing folder, it will serve it normally, by redirecting the user to its index page, or displaying an automatic index or something. Eventually if both RewriteConditions are met, then Apache will rewrite the URI by internally redirecting the request to index.php (and automatically appending the arguments to the URL).
We could write a similar script for Nginx with if's and rewrite instructions, but the best practice is to use the try_files directive:
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
What this does is:
1) Nginx attempts to serve $uri (the requested URI)
2) If the above doesn't exist, it attempts to load $uri/ (note the slash for a potential folder)
3) If the above doesn't exist, it loads /index.php?q=$uri&$args (the index.php page, transferring the request arguments too)
An average working (tested) server block for serving LimeSurvey would be:
server {
listen 80;
server_name mywebsite.com;
root /var/www/mywebsitefiles;
index index.php;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi.conf;
}
}
Make sure to replace my example values by your own; if you are unsure about the meaning of the directives you should consult the Nginx wiki. Save your configuration file and reload Nginx to apply the changes.
Note: if you allow file uploads from users, you should better secure the "location ~* \.php$" line by specifying from which folders PHP files may be executed. Otherwise your server might be at risk depending on the files you allow your users to upload (ie. if you allow them to upload PHP files).
After installing LimeSurvey
Whether you install LimeSurvey after or before applying the Nginx rewrite rules doesn't matter: the LimeSurvey install script will detect that your server isn't running Apache's mod_rewrite anyway, so it will automatically switch off the "fancy URLs" functionality.
In order to enable it, open /application/config/config.php and change the following values:
'urlFormat' => 'get',
change this line to:
'urlFormat' => 'path',
And then:
'showScriptName' => true,
to the following line:
'showScriptName' => false,
After doing so, try visiting yourwebsite.com/admin/ and you should be taken to Limesurvey's administration panel. If your browser isn't loading the page properly you might have to clear your browser cache.
I have tested this myself and haven't run into issues so far.
Comments
Thanks
I was migrating my installation from Apache to Nginx due to performance issues...
Many thanks!
----
five nights at freddy's | fnaf 3 | five nights at freddy's game
----
descargar mobogenie gratis and apply baixar facebook gratis | descargar mobogenie