Difference between revisions of "Nginx"
From Joomla! Documentation
(Fixed the shitty English and crappy style) |
m (Deleted duplicate header and unnecessary nginx.conf outdent) |
||
Line 17: | Line 17: | ||
== Configure Nginx == | == Configure Nginx == | ||
− | |||
− | |||
nginx configuration files reside in: | nginx configuration files reside in: | ||
* <tt>/usr/local/nginx/conf/</tt> on Ubuntu | * <tt>/usr/local/nginx/conf/</tt> on Ubuntu | ||
Line 26: | Line 24: | ||
<pre> | <pre> | ||
− | + | server { | |
− | + | listen 80; | |
− | + | server_name YOUR_DOMAIN; | |
− | + | server_name_in_redirect off; | |
− | + | access_log /var/log/nginx/localhost.access_log main; | |
− | + | error_log /var/log/nginx/localhost.error_log info; | |
− | + | root PATH_ON_SERVER; | |
− | + | # Support Clean URLs (aka Search Engine Friendly) | |
− | + | location / { | |
− | + | try_files $uri $uri/ /index.php?q=$request_uri; | |
− | + | } | |
− | + | index index.php index.html index.htm default.html default.htm; | |
− | + | # deny running scripts inside writable directories | |
− | + | location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ { | |
− | + | return 403; | |
− | + | error_page 403 /403_error.html; | |
− | + | } | |
− | + | location ~ .*.php$ { | |
− | + | include /etc/nginx/fastcgi.conf; | |
− | + | fastcgi_pass 127.0.0.1:9000; | |
− | + | fastcgi_index index.php; | |
− | + | include fastcgi_params; | |
− | + | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
− | + | } | |
− | + | # caching of files | |
− | + | location ~* \.(ico|pdf|flv)$ { | |
− | + | expires 1y; | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
+ | location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ { | ||
+ | expires 14d; | ||
} | } | ||
+ | } | ||
</pre> | </pre> | ||
Revision as of 05:37, 16 August 2011
nginx is a lightweight web server that powers 7.5% of web servers across all domains[1]. Unless you have specific requirements that demand a heavy web server like Apache, you are much better off using nginx.
Below are instructions on how to get Joomla! running with nginx and PHP via FastCGI.
Install nginx[edit]
For Ubuntu, run aptitude install nginx. For other distros, run the corresponding package manager, or see http://wiki.nginx.org/Install.
Install PHP FastCGI[edit]
For Ubuntu, read this excellent page on how to configure PHP and FastCGI for nginx.
For Gentoo, PHP will run as a FastCGI service (fpm), so the nginx server will run PHP asa different process:
# echo "dev-lang/php gd gd2 curl simplexml tokenizer dom tidy sqlite xml fpm cgi" >> /etc/portage/package.use # emerge php
The default settings of php-fpm are good for most servers. For special configuration visit the PHP FPM site.
Configure Nginx[edit]
nginx configuration files reside in:
- /usr/local/nginx/conf/ on Ubuntu
- /etc/nginx/nginx.conf on Gentoo
Here is an sample nginx configuration file.
server { listen 80; server_name YOUR_DOMAIN; server_name_in_redirect off; access_log /var/log/nginx/localhost.access_log main; error_log /var/log/nginx/localhost.error_log info; root PATH_ON_SERVER; # Support Clean URLs (aka Search Engine Friendly) location / { try_files $uri $uri/ /index.php?q=$request_uri; } index index.php index.html index.htm default.html default.htm; # deny running scripts inside writable directories location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ { return 403; error_page 403 /403_error.html; } location ~ .*.php$ { include /etc/nginx/fastcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # caching of files location ~* \.(ico|pdf|flv)$ { expires 1y; } location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ { expires 14d; } }
Pay attention for few things:
- The parameter fastcgi_pass is set to 127.0.0.1:9000, corresponding to the port that fpm is configured to listen to. This means you can run the PHP processes on separate servers. On Gentoo, you can find this configuration in /etc/php/fpm-php5.3/php-fpm.conf/
- Don't forget to replace YOUR_DOMAIN & PATH_ON_SERVER depend on your domain and the path of Joomla on your server.
GZip support[edit]
If you need GZip compression support, add the following section to the http section of the main nginx configuration file:
gzip on; gzip_http_version 1.1; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 4 8k; gzip_types text/plain application/xhtml+xml text/css application/xml application/xml+rss text/javascript application/javascript application/x-javascr$ gzip_proxied any; gzip_disable "MSIE [1-6]\.";