Nginx: Difference between revisions
From Joomla! Documentation
m added Category:Server configurations using HotCat |
Some markup changes and URL corrections. |
||
| Line 1: | Line 1: | ||
<noinclude><languages /></noinclude> | <noinclude><languages /></noinclude> | ||
<translate><!--T:1--> | <translate><!--T:1--> | ||
[http://nginx.net/ | [http://nginx.net/ Nginx] is a lightweight Web server that powers about 13% of Web servers across all domains[https://en.wikipedia.org/wiki/Nginx]. Unless you have specific requirements that demand a heavy Web server like Apache, you are much better off using Nginx.</translate> | ||
<translate><!--T:2--> | <translate><!--T:2--> | ||
Below are instructions on how to get Joomla! running with [ | Below are instructions on how to get Joomla! running with [https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/ PHP FastCGI Example].</translate> | ||
<translate> | <translate> | ||
== Install | == Install Nginx == <!--T:3--> | ||
</translate> | </translate> | ||
<translate><!--T:4--> | <translate><!--T:4--> | ||
For Ubuntu, run | For Ubuntu, run ''aptitude install Nginx''. For other distributions, run the corresponding package manager, or see http://wiki.nginx.org/Install.</translate> | ||
<translate> | <translate> | ||
| Line 16: | Line 16: | ||
</translate> | </translate> | ||
<translate><!--T:6--> | <translate><!--T:6--> | ||
For Ubuntu, read | For Ubuntu, read [https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/ PHP FastCGI Example].</translate> | ||
<translate><!--T:7--> | <translate><!--T:7--> | ||
For Gentoo, PHP will run as a FastCGI service ( | For Gentoo, PHP will run as a FastCGI service (FPM), so the Nginx server will run PHP as a separate process:</translate> | ||
<pre> | <pre> | ||
# echo "dev-lang/php gd gd2 curl simplexml tokenizer dom tidy sqlite xml fpm cgi" >> /etc/portage/package.use | # echo "dev-lang/php gd gd2 curl simplexml tokenizer dom tidy sqlite xml fpm cgi" >> /etc/portage/package.use | ||
| Line 25: | Line 25: | ||
</pre> | </pre> | ||
<translate><!--T:8--> | <translate><!--T:8--> | ||
The default settings of | The default settings of PHP-FPM are good for most servers. For special configurations, visit the [http://php.net/manual/en/install.fpm.php PHP FPM site].</translate> | ||
<translate> | <translate> | ||
| Line 31: | Line 31: | ||
</translate> | </translate> | ||
<translate><!--T:10--> | <translate><!--T:10--> | ||
Nginx configuration files reside in:</translate> | |||
<translate><!--T:11--> | <translate><!--T:11--> | ||
* <tt>/etc/nginx/sites-available/</tt> on Ubuntu (for sites running on that | * <tt>/etc/nginx/sites-available/</tt> on Ubuntu (for sites running on that Nginx instance)</translate> | ||
<translate><!--T:12--> | <translate><!--T:12--> | ||
* <tt>/etc/nginx/nginx.conf</tt> on Gentoo and Raspbian( | * <tt>/etc/nginx/nginx.conf</tt> on Gentoo and Raspbian (Debian optimized for Raspberry Pi)</translate> | ||
<translate><!--T:13--> | <translate><!--T:13--> | ||
Here is an sample | Here is an sample Nginx configuration file, ''joomla.conf'', that you can reuse over all your Nginx enabled-sites.</translate> | ||
<pre> | <pre> | ||
| Line 88: | Line 88: | ||
Pay attention to a few things:</translate> | Pay attention to a few things:</translate> | ||
<translate><!--T:15--> | <translate><!--T:15--> | ||
# The parameter | # 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 the ''/etc/php/fpm-php5.3/php-fpm.conf/'' file.</translate> | ||
<translate><!--T:16--> | <translate><!--T:16--> | ||
# Don't forget to replace YOUR_DOMAIN & PATH_ON_SERVER above depending on your domain and the path of Joomla on your server.</translate> | # Don't forget to replace YOUR_DOMAIN & PATH_ON_SERVER above depending on your domain and the path of Joomla on your server.</translate> | ||
<translate> | <translate> | ||
== GZip | == GZip Support == <!--T:17--> | ||
</translate> | </translate> | ||
<translate><!--T:18--> | <translate><!--T:18--> | ||
If you need GZip compression support, add the following section to the http section of the main | If you need GZip compression support, add the following section to the ''http'' section of the main Nginx configuration file:</translate> | ||
<pre> | <pre> | ||
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-javascript | |||
gzip_proxied any; | |||
gzip_disable "MSIE [1-6]\."; | |||
</pre> | </pre> | ||
| Line 112: | Line 112: | ||
</translate> | </translate> | ||
* [http://en.gentoo-wiki.com/wiki/Nginx Nginx in Gentoo] | * [http://en.gentoo-wiki.com/wiki/Nginx Nginx in Gentoo] | ||
* [ | * [https://kevinworthington.com/nginx-for-windows/ Nginx for Windows] | ||
* [http://wiki.nginx.org/Install#Ubuntu_PPA Nginx in Ubuntu] | * [http://wiki.nginx.org/Install#Ubuntu_PPA Nginx in Ubuntu] | ||
* [ | * [https://www.debianadmin.com/howto-install-nginx-webserver-in-debian.html Nginx in Debian] | ||
* [ | * [https://www.php.net/manual/en/install.fpm.php PHP-FPM installation and configuration] | ||
* [http:// | * [http://nginx.org/en/docs/http/ngx_http_gzip_module.html GZip in Nginx] | ||
* [http:// | * [http://nginx.org/en/docs/http/ngx_http_rewrite_module.html Rewrite in Nginx] | ||
* [http://nginx.org/en/docs/http/request_processing.html How | * [http://nginx.org/en/docs/http/request_processing.html How Nginx processes a request] | ||
[[Category:Server configurations]] | [[Category:Server configurations]] | ||
Revision as of 21:27, 10 August 2022
Nginx is a lightweight Web server that powers about 13% 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 PHP FastCGI Example.
Install Nginx
For Ubuntu, run aptitude install Nginx. For other distributions, run the corresponding package manager, or see http://wiki.nginx.org/Install.
Install PHP FastCGI
For Ubuntu, read PHP FastCGI Example.
For Gentoo, PHP will run as a FastCGI service (FPM), so the Nginx server will run PHP as a separate 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 configurations, visit the PHP FPM site.
Configure Nginx
Nginx configuration files reside in:
- /etc/nginx/sites-available/ on Ubuntu (for sites running on that Nginx instance)
- /etc/nginx/nginx.conf on Gentoo and Raspbian (Debian optimized for Raspberry Pi)
Here is an sample Nginx configuration file, joomla.conf, that you can reuse over all your Nginx enabled-sites.
server {
listen 80;
server_name YOUR_DOMAIN;
server_name_in_redirect off;
access_log /var/log/nginx/localhost.access_log;
error_log /var/log/nginx/localhost.error_log info;
root PATH_ON_SERVER;
index index.php index.html index.htm default.html default.htm;
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
# add global x-content-type-options header
add_header X-Content-Type-Options nosniff;
# 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$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi.conf;
}
# caching of files
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
}
Pay attention to a 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 the /etc/php/fpm-php5.3/php-fpm.conf/ file.
- Don't forget to replace YOUR_DOMAIN & PATH_ON_SERVER above depending on your domain and the path of Joomla on your server.
GZip Support
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-javascript gzip_proxied any; gzip_disable "MSIE [1-6]\.";