-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.bash
147 lines (145 loc) · 4.98 KB
/
menu.bash
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
clear
echo "#########################################
# Nginx Web Server Management Menu #
#########################################
1. Install Nginx
2. Install PHP
3. Add a Domain
4. Remove a Domain
5. Add Reverse Proxy
6. Remove Reverse Proxy
7. Add SSL certificate
8. Connecting SSL
9. Exit
"
while true; do
read -p "Enter your choice [1-9]: " choice
case $choice in
1)
# Install Nginx
echo "Available Nginx versions: 1.18.0, 1.19.5, 1.20.2"
read -p "Enter the Nginx version you want to install (e.g. 1.20.2): " nginx_version
echo "Installing Nginx $nginx_version..."
sudo apt-get update
sudo apt-get install nginx=$nginx_version-*
echo "Nginx $nginx_version has been installed."
;;
2)
# Install PHP
echo "Available PHP versions: 7.2, 7.4, 8.0"
read -p "Enter the PHP version you want to install (e.g. 7.4): " php_version
echo "Installing PHP $php_version..."
sudo apt-get install php$php_version-fpm php$php_version-mysql php$php_version-gd php$php_version-curl php$php_version-json php$php_version-mbstring php$php_version-xml
echo "PHP $php_version has been installed."
;;
3)
# Add a Domain
read -p "Enter the domain name: " domain
# Create a folder for the domain
sudo mkdir -p /var/www/$domain
echo "Folder for $domain has been created. (/var/www/$domain)"
sudo rm /etc/nginx/sites-enabled/$domain
echo -n "server {
listen 80;
server_name $domain;
root /var/www/$domain;
# logging
access_log /var/log/nginx/$domain.access.log;
error_log /var/log/nginx/$domain.error.log warn;
# index
index index.php index.html index.htm default.php default.htm default.html;
# handle .php
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
}" | sudo tee -a /etc/nginx/sites-enabled/$domain
sudo service nginx restart
;;
4)
# Remove a Domain
read -p "Enter the domain name: " domain
# Remove the folder for the domain
echo "Removing the folder for $domain..."
sudo rm -rf /var/www/$domain
sudo rm /etc/nginx/sites-enabled/$domain
sudo rm /var/log/nginx/$domain.access.log;
sudo rm /var/log/nginx/$domain.error.log;
sudo rm /etc/nginx/ssl/$domain.crt;
sudo rm /etc/nginx/ssl/$domain.key;
echo "Folder for $domain has been removed."
;;
5)
# Add Reverse Proxy
read -p "Enter the domain name: " domain
read -p "Enter the IP: " IPdomain
echo "Adding reverse proxy for $domain..."
# Add the following code to the Nginx configuration:
sudo rm /etc/nginx/sites-enabled/$domain
echo -n "server {
listen 80;
server_name $domain;
location / {
proxy_pass http://$IPdomain:80;
}
}" | sudo tee -a /etc/nginx/sites-enabled/$domain
# Save and exit the configuration file
# Restart Nginx to apply changes
sudo service nginx restart
echo "Reverse proxy has been added for $domain."
;;
6)
# Remove Reverse Proxy
read -p "Enter the domain name: " domain
sudo rm /etc/nginx/sites-enabled/$domain
# Save and exit the configuration file
# Restart Nginx to apply changes
sudo service nginx restart
echo "Reverse proxy has been removed for $domain."
;;
7)
# Create SSL certificate
read -p "Enter the domain name for the SSL certificate: " domain
echo "Creating SSL certificate for $domain..."
sudo mkdir -p /etc/nginx/ssl/
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/$domain.key -out /etc/nginx/ssl/$domain.crt
echo "SSL certificate for $domain has been created."
;;
8)
# Connect SSL certificate
read -p "Enter the domain name to connect the SSL certificate to: " domain
sudo rm /etc/nginx/sites-enabled/$domain
echo "Connecting SSL certificate to $domain..."
echo -n "server {
listen 80;
listen 443 ssl;
server_name $domain;
root /var/www/$domain;
ssl_certificate /etc/nginx/ssl/$domain.crt;
ssl_certificate_key /etc/nginx/ssl/$domain.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
# logging
access_log /var/log/nginx/$domain.access.log;
error_log /var/log/nginx/$domain.error.log warn;
# index
index index.php index.html index.htm default.php default.htm default.html;
# handle .php
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
}" | sudo tee -a /etc/nginx/sites-enabled/$domain
sudo systemctl reload nginx
echo "SSL certificate has been connected to $domain."
;;
9)
# Exit
break
;;
*)
echo "Invalid choice. Please enter a number between 1 and 9."
;;
esac
done