2 # Friendica Nginx configuration template to be autoconfigured with certbot
3 # based on sample-nginx.config by Olaf Conradi
5 # On Debian based distributions you can add this file to
6 # /etc/nginx/sites-available
8 # Then customize it to your needs. At least replace the server_name in line 41.
10 # Enable the configuration by
11 # symlink it to /etc/nginx/sites-enabled
14 # certbot --nginx -d friendica.example.net
16 # Then reload Nginx using
17 # systemctl nginx reload
22 # You should look at the following URL's in order to grasp a solid understanding
23 # of Nginx configuration files in order to fully unleash the power of Nginx.
25 # http://wiki.nginx.org/Pitfalls
26 # http://wiki.nginx.org/QuickStart
27 # http://wiki.nginx.org/Configuration
31 # This configuration assumes your domain is example.net
32 # You have a separate subdomain friendica.example.net
33 # You want all Friendica traffic to be https using letsencrypt with cerbot
34 # You have an SSL certificate and key for your subdomain
35 # You have PHP FastCGI Process Manager (php7.4-fpm) running on localhost
36 # You have Friendica installed in /var/www/friendica
40 # by https://syshero.org/2018-04-13-nginx-unique-request-identifier/
41 # if X-Request-ID is set, NGINX will forward the same value to the next upstream
42 # if the header is not set, NGINX will generate a random request identifier and add it to the request.
44 # To guarantee backward compatibility, map to format the $request_id variable to a format that matches any old setups.
47 map $request_id $formatted_id {
48 "~*(?<p1>[0-9a-f]{8})(?<p2>[0-9a-f]{4})(?<p3>[0-9a-f]{4})(?<p4>[0-9a-f]{4})(?<p5>.*)$" "${p1}-${p2}-${p3}-${p4}-${p5}";
51 map $http_x_request_id $uuid {
52 default "${request_id}";
53 ~* "${http_x_request_id}";
58 server_name friendica.example.net;
60 # Point here to the path where your friendica files are located
61 root /var/www/friendica;
64 access_log /var/log/nginx/friendica_access.log;
65 # uncomment the following line if you would like to log errors in a separate file for friendica
66 #error_log /var/log/nginx/friendica_error.log;
71 # Uncomment the following line to include a standard configuration file Note
72 # that the most specific rule wins and your standard configuration will
73 # therefore *add* to this file, but not override it.
74 #include standard.conf
76 # allow uploads up to 20MB in size
77 client_max_body_size 20m;
78 client_body_buffer_size 128k;
80 # add the request id header to show it in the HTTP header output
81 add_header X-Request-ID $uuid;
83 # rewrite to front controller as default rule
85 try_files $uri /index.php?pagename=$uri&$args;
88 # make sure webfinger and other well known services aren't blocked
89 # by denying dot files and rewrite request to the front controller
90 location ^~ /.well-known/ {
92 rewrite ^ /index.php?pagename=$uri;
97 # statically serve these file types when possible otherwise fall back to
98 # front controller allow browser to cache them added .htm for advanced source
100 #location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {
102 # try_files $uri /index.php?pagename=$uri&$args;
105 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
108 # Zero-day exploit defense.
109 # http://forum.nginx.org/read.php?2,88845,page=3
110 # Won't work properly (404 error) if the file is not stored on this
111 # server, which is entirely possible with php-fpm/php-fcgi.
112 # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on
113 # another machine. And then cross your fingers that you won't get hacked.
116 # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
117 fastcgi_split_path_info ^(.+\.php)(/.+)$;
119 # With php5-cgi alone:
120 # fastcgi_pass 127.0.0.1:9000;
123 fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
125 include fastcgi_params;
126 fastcgi_index index.php;
127 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
129 fastcgi_param HTTP_X_REQUEST_ID $uuid;
131 fastcgi_buffers 16 16k;
132 fastcgi_buffer_size 32k;
135 # block these file types
136 location ~* \.(tpl|md|tgz|log|out)$ {
140 # deny access to all dot files
145 # deny access to the CLI scripts