<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="sv">
	<id>https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matmercer</id>
	<title>MoodleDocs - Användarbidrag [sv]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matmercer"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/Special:Bidrag/Matmercer"/>
	<updated>2026-05-12T03:21:29Z</updated>
	<subtitle>Användarbidrag</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=141607</id>
		<title>Nginx</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=141607"/>
		<updated>2021-08-29T04:23:10Z</updated>

		<summary type="html">&lt;p&gt;Matmercer: The guide had incorrect alias definition. I had to add a different alias definition of NGINX to it work correctly. This solves https://moodle.org/mod/forum/discuss.php?d=349925 and https://moodle.org/mod/forum/discuss.php?d=413492&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}[[Nginx]] [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. The nginx project started with a strong focus on high concurrency, high performance and low memory usage. It is licensed under the 2-clause BSD-like license and it runs on Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, as well as on other *nix flavours. It also has a proof of concept port for Microsoft Windows.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following is community-contributed documentation on Nginx configuration. Amendments and additions are welcome.&#039;&#039;&lt;br /&gt;
== Nginx configuration ==&lt;br /&gt;
=== PHP-FPM ===&lt;br /&gt;
Nginx is usually configured to interface with PHP via [http://php.net/manual/en/install.fpm.php php-fpm]. This is both fast and robust.&lt;br /&gt;
&lt;br /&gt;
PHP-FPM&#039;s default behaviour for pools is usually to restrict the execution of scripts to a specific extension, i.e. .php. You should ensure that this behaviour is configured within your particular package/distribution, e.g. for debian,&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/etc/php5/fpm/pool.d/www.conf&#039;&#039;&#039;&lt;br /&gt;
 security.limit_extensions = .php&lt;br /&gt;
=== Nginx ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following &#039;slash arguments&#039; compatible &#039;location&#039; block to your vhosts &#039;server&#039; in your nginx configuration (further explanation at &#039;[[Using slash arguments]]&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;nginx.conf location:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ [^/]\.php(/|$) {&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000 (or your php-fpm socket);&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the above does not work try the following:&lt;br /&gt;
Note: This was for CentOS 7.6 (1804), MariaDB 10.3, Nginx 1.15 and PHP 7.3.5&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ ^(.+\.php)(.*)$ {&lt;br /&gt;
    root /usr/share/nginx/html/moodle/;&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(.*)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000;&lt;br /&gt;
    include /etc/nginx/mime.types;&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you find that this does not work (scripts, styles, and images not loading) &#039;&#039;&#039;and&#039;&#039;&#039; that there are &amp;lt;code&amp;gt;open() &amp;quot;...&amp;quot; failed (20: Not a directory)&amp;lt;/code&amp;gt; lines appearing in your logs: Check whether there are any directives related to static content &#039;&#039;&#039;before&#039;&#039;&#039; this block and try moving them &#039;&#039;&#039;after&#039;&#039;&#039; this block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another potential pitfall is the use of &#039;&#039;&#039;try_files&#039;&#039;&#039;. Many guides recommend configurations like &amp;lt;pre&amp;gt;try_files $fastcgi_script_name =404;&amp;lt;/pre&amp;gt;. But if try_files is used, nginx deletes the content of the &#039;&#039;&#039;$fastcgi_path_info&#039;&#039;&#039; variable (this is [https://trac.nginx.org/nginx/ticket/321 intended behavior]). This causes &#039;&#039;&#039;PATH_INFO&#039;&#039;&#039; to also be empty, so slash arguments don&#039;t work.&lt;br /&gt;
An alternative is the use of &amp;lt;pre&amp;gt;if(!-f $document_root$fastcgi_script_name) {return 404;}&amp;lt;/pre&amp;gt; [https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/#connecting-nginx-to-php-fpm as recommended] by the nginx documentation, although the nginx documentation also recommends [https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ not using if].&lt;br /&gt;
==== Error pages ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This passes 404 pages to Moodle so they can be themed&lt;br /&gt;
error_page 404 /error/index.php;    error_page 403 =404 /error/index.php;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Hiding internal files ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Hide all dot files but allow &amp;quot;Well-Known URIs&amp;quot; as per RFC 5785&lt;br /&gt;
location ~ /\.(?!well-known).* {&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
# This should be after the php fpm rule and very close to the last nginx ruleset.&lt;br /&gt;
# Don&#039;t allow direct access to various internal files. See MDL-69333&lt;br /&gt;
location ~ (/vendor/|/node_modules/|composer\.json|/readme|/README|readme\.txt|/upgrade\.txt|db/install\.xml|/fixtures/|/behat/|phpunit\.xml|\.lock|environment\.xml) {&lt;br /&gt;
    deny all;&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== XSendfile aka X-Accel-Redirect ====&lt;br /&gt;
Setting Moodle and Nginx to use XSendfile functionality is a big win as it frees PHP from delivering files allowing Nginx to do what it does best, i.e. deliver files. &lt;br /&gt;
&lt;br /&gt;
Enable xsendfile for Nginx in Moodles config.php, this is documented in the config-dist.php, a minimal configuration look like this,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;&lt;br /&gt;
$CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
    &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Accompany this with a matching &#039;location&#039; block in your nginx server configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ ^/dataroot/(.*)$ {&lt;br /&gt;
    # The definition of &#039;internal&#039; here is CRITICAL as it prevents client access to your dataroot.&lt;br /&gt;
    internal;&lt;br /&gt;
    alias &amp;lt;full_moodledata_path&amp;gt;/$1; # ensure the path ends with &#039;/$1&#039;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The definition of &#039;internal&#039; here is &#039;&#039;&#039;critical&#039;&#039;&#039; as it prevents client access to your dataroot.&lt;br /&gt;
== See also ==&lt;br /&gt;
* Real &amp;lt;tt&amp;gt;PATH_INFO&amp;lt;/tt&amp;gt; support:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=278916&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=307388&lt;br /&gt;
* &#039;&#039;&#039;[Deprecated]&#039;&#039;&#039; Internal rewriting to the HTTP GET &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=83445&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[es:Nginx]]&lt;br /&gt;
[[pt-br:Nginx]]&lt;/div&gt;</summary>
		<author><name>Matmercer</name></author>
	</entry>
</feed>