-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7-puppet_install_nginx_web_server.pp
executable file
·79 lines (70 loc) · 2.03 KB
/
7-puppet_install_nginx_web_server.pp
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
# add stable version of nginx
exec { 'add nginx stable repo':
command => 'sudo add-apt-repository ppa:nginx/stable',
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
# update software packages list
exec { 'update packages':
command => 'apt-get update',
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
# install nginx
package { 'nginx':
ensure => 'installed',
}
# allow HTTP
exec { 'allow HTTP':
command => "ufw allow 'Nginx HTTP'",
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
onlyif => '! dpkg -l nginx | egrep \'îi.*nginx\' > /dev/null 2>&1',
}
# change folder rights
exec { 'chmod www folder':
command => 'chmod -R 755 /var/www',
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
# create index file
file { '/var/www/html/index.html':
content => "Hello World!\n",
}
# create index file
file { '/var/www/html/404.html':
content => "Ceci n'est pas une page\n",
}
# add redirection and error page
file { 'Nginx default config file':
ensure => file,
path => '/etc/nginx/sites-enabled/default',
content =>
"server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files \$uri \$uri/ =404;
}
error_page 404 /404.html;
location /404.html {
internal;
}
if (\$request_filename ~ redirect_me){
rewrite ^ https://www.youtube.com/@tpauldike permanent;
}
}
",
}
# restart nginx
exec { 'restart service':
command => 'service nginx restart',
path => '/usr/bin:/usr/sbin:/bin',
}
# start service nginx
service { 'nginx':
ensure => running,
require => Package['nginx'],
}