]> git.mxchange.org Git - friendica.git/blob - mods/sample-nginx-certbot.config
Changes:
[friendica.git] / mods / sample-nginx-certbot.config
1 ##
2 # Friendica Nginx configuration template to be autoconfigured with certbot
3 # based on sample-nginx.config by Olaf Conradi
4 #
5 # On Debian based distributions you can add this file to
6 # /etc/nginx/sites-available
7 #
8 # Then customize it to your needs. At least replace the server_name in line 41.
9 #
10 # Enable the configuration by
11 # symlink it to /etc/nginx/sites-enabled
12 #
13 # and run
14 # certbot --nginx -d friendica.example.net
15 #
16 # Then reload Nginx using
17 # systemctl nginx reload
18 #
19 ##
20
21 ##
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.
24 #
25 # http://wiki.nginx.org/Pitfalls
26 # http://wiki.nginx.org/QuickStart
27 # http://wiki.nginx.org/Configuration
28 ##
29
30 ##
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 certbot
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
37 ##
38
39 ##
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.
43 #
44 # To guarantee backward compatibility, map to format the $request_id variable to a format that matches any old setups.
45 ##
46
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}";
49 }
50
51 map $http_x_request_id $uuid {
52   default   "${request_id}";
53   ~*        "${http_x_request_id}";
54 }
55
56 server {
57   listen 80;
58   server_name friendica.example.net;
59
60   # Point here to the path where your friendica files are located
61   root /var/www/friendica;
62
63   # Logging
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;
67
68   index index.php;
69   charset utf-8;
70
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
75
76   # allow uploads up to 20MB in size
77   client_max_body_size 20m;
78   client_body_buffer_size 128k;
79         
80         # add the request id header to show it in the HTTP header output
81   add_header X-Request-ID $uuid;
82
83   # rewrite to front controller as default rule
84   location / {
85     try_files $uri /index.php?pagename=$uri&$args;
86   }
87
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/ {
91     allow all;
92     rewrite ^ /index.php?pagename=$uri;
93   }
94
95   include mime.types;
96
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
99   # code editor library
100   #location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {
101   #  expires 30d;
102   #  try_files $uri /index.php?pagename=$uri&$args;
103   #}
104
105   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
106   # or a unix socket
107   location ~* \.php$ {
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.
114     try_files $uri =404;
115
116     # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
117     fastcgi_split_path_info ^(.+\.php)(/.+)$;
118
119     # With php5-cgi alone:
120     # fastcgi_pass 127.0.0.1:9000;
121
122     # With php7.4-fpm:
123     fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
124
125     include fastcgi_params;
126     fastcgi_index index.php;
127     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
128                 
129                 fastcgi_param HTTP_X_REQUEST_ID $uuid;
130
131     fastcgi_buffers 16 16k;
132     fastcgi_buffer_size 32k;
133   }
134
135   # block these file types
136   location ~* \.(tpl|md|tgz|log|out)$ {
137     deny all;
138   }
139
140   # deny access to all dot files
141   location ~ /\. {
142     deny all;
143    }
144
145    # deny access to the CLI scripts
146   location ^~ /bin {
147     deny all;
148   }
149 }
150