-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25-nginx
executable file
·133 lines (105 loc) · 2.87 KB
/
25-nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Create configuration based on domain name
DOMAIN_NAME=$(cat /config/domain_name)
USES_SSL=0
if [ -e /config/cert.pem ]; then
if [ -e /config/cert.key ]; then
echo "Enabling SSL due to presence of certificates!"
USES_SSL=1
fi
fi
if [ $USES_SSL -eq 1 ]; then
cat >/etc/nginx/nginx.conf <<EOF
worker_processes 1;
error_log /var/log/nginx/error.log;
events { worker_connections 256; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 15;
client_max_body_size 5m;
passenger_root /srv/diaspora/.rvm/gems/ruby-2.1.5@diaspora/gems/passenger-5.0.13;
passenger_ruby /srv/diaspora/.rvm/gems/ruby-2.1.5@diaspora/wrappers/ruby;
server {
listen 80;
rewrite ^/(.*) https://$DOMAIN_NAME/\$1 permanent;
}
upstream thin_cluster {
server localhost:3000;
}
server {
listen 443 ssl;
ssl on;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/certs/server.key;
passenger_enabled on;
rails_env production;
root /srv/diaspora/diaspora/public;
error_log /var/log/nginx/diaspora.error-ssl.log;
access_log /var/log/nginx/diaspora.access-ssl.log;
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; }
location /uploads/images {
expires 1d;
add_header Cache-Control public;
}
location /assets {
expires 1d;
add_header Cache-Control public;
}
}
}
EOF
else
cat >/etc/nginx/nginx.conf <<EOF
worker_processes 1;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
events { worker_connections 256; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 15;
client_max_body_size 5m;
passenger_root /srv/diaspora/.rvm/gems/ruby-2.1.5@diaspora/gems/passenger-5.0.13;
passenger_ruby /srv/diaspora/.rvm/gems/ruby-2.1.5@diaspora/wrappers/ruby;
upstream thin_cluster {
server localhost:3000;
}
server {
listen 80;
passenger_enabled on;
rails_env production;
root /srv/diaspora/diaspora/public;
error_log /var/log/nginx/diaspora.error.log;
access_log /var/log/nginx/diaspora.access.log;
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; }
location /uploads/images {
expires 1d;
add_header Cache-Control public;
}
location /assets {
expires 1d;
add_header Cache-Control public;
}
}
}
EOF
fi
# Check syntax
/srv/diaspora/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
if [ $? -ne 0 ]; then
echo "Nginx syntax check fail"
exit 1
fi
# Run Nginx
/srv/diaspora/nginx/sbin/nginx -c /etc/nginx/nginx.conf
# Wait for /run/nginx.pid to appear and copy it.
while [ ! -e /run/nginx.pid ]; do
echo "Waiting for /run/nginx.pid to appear..."
sleep 1
done
cp /run/nginx.pid /run/watch/nginx