]> git.mxchange.org Git - friendica.git/blob - mods/sample-nginx.config
add sample nginx config from Olaf Conradi to mods directory
[friendica.git] / mods / sample-nginx.config
1 From: Olaf Conradi
2 Hey @Friendica Support,
3
4 Just wanted to share my #nginx configuration for #friendica with you guys.
5
6 I noticed most of the existing configurations that are floating on the web for #nginx do not deny access to local files. Most of them use the following construct.
7
8 location / {
9   try_files $uri $uri/ index.php?q=$request_uri
10 }
11
12 This serves files like images statically, but also gives everyone access to the source code of your ~friendica ~friendica installation (tpl templates, sql files, etc). One should deny all locations except for images, javascript and css files. Setting these deny rules is tedious and needs maintenance when new directories are added.
13
14 It's easier to route everything through the front controller except those known file types.
15
16 Below is my configuration. First I forward non-SSL traffic to SSL.
17
18 server {
19   server_name friendica.example.net;
20   index index.php;
21   root /mnt/friendica/www;
22   rewrite ^ https://friendica.example.net$request_uri? permanent;
23 }
24
25 Next is the SSL server part.
26
27 server {
28   listen 443 ssl;
29   server_name friendica.example.net;
30
31   index index.php;
32   root /mnt/friendica/www;
33
34   ssl on;
35   ssl_certificate /etc/nginx/ssl/friendica.example.net.chain.pem;
36   ssl_certificate_key /etc/nginx/ssl/example.net.key;
37   ssl_session_timeout 5m;
38   ssl_protocols SSLv3 TLSv1;
39   ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
40   ssl_prefer_server_ciphers on;
41
42   # allow uploads up to 20MB in size
43   client_max_body_size 20m;
44   client_body_buffer_size 128k;
45
46   # rewrite to front controller as default rule
47   location / {
48     rewrite ^/(.*) /index.php?q=$1 last;
49   }
50
51   # make sure webfinger isn't blocked by denying dot files
52   # and rewrite to front controller
53   location = /.well-known/host-meta {
54     allow all;
55     rewrite ^/(.*) /index.php?q=$1 last;
56   }
57
58   # statically serve these file types
59   # allow browser to cache them
60   # added .htm for advanced source code editor library
61   location ~* \.(jpg|jpeg|gif|png|css|js|ico|htm)$ {
62     expires 30d;
63   }
64
65   # block these file types
66   location ~* \.(tpl|md|git|tgz) {
67     deny all;
68   }
69
70   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
71   location ~* \.php$ {
72     fastcgi_split_path_info ^(.+\.php)(/.+)$;
73     # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
74     # # With php5-cgi alone:
75     # fastcgi_pass 127.0.0.1:9000;
76     # With php5-fpm:
77     fastcgi_pass unix:/var/run/php5-fpm.sock;
78     fastcgi_index index.php;
79     include fastcgi_params;
80   }
81
82   # deny access to all dot files (including .htaccess)
83   location ~ /\. {
84     deny all;
85   }
86 }
87
88 That's it.
89 #nginx #friendica @Friendica Support
90
91
92 I found one bug after posting when I noticed 404's coming in for certain image files. Avatars need a fallback to go through the front controller.
93 # statically serve these file types when possible
94 # otherwise fall back to front controller
95 # allow browser to cache them
96 # added .htm for advanced source code editor library
97 location ~* \.(jpg|jpeg|gif|png|css|js|ico|htm)$ {
98 expires 30d;
99 try_files $uri /index.php?q=$request_uri?;
100 }
101