Skip to content

Commit 8c6b475

Browse files
author
Королёв Олег
committed
my chanegs
1 parent 12a0d58 commit 8c6b475

File tree

3 files changed

+188
-162
lines changed

3 files changed

+188
-162
lines changed

nginx-vhost/nginx-vhost.sh

100644100755
Lines changed: 136 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,167 @@
11
#!/bin/bash
2-
VHOST_DIR='/etc/nginx/sites-available'
3-
USER_DIR='/ebs/www'
4-
USERNAME=''
5-
USERPASS=''
2+
USER_DIR='/Users/ruscon'
63
DOMAIN=''
7-
MSYQLPASS=''
84
USER_TRUNC=''
95
DOMAIN_TRUNC=''
106
DB_PASS=''
117

128
RET=''
139
function sanity_check {
14-
if [ "$(id -u)" != "0" ]; then
15-
echo "Script must be run as root."
16-
exit 1
17-
fi
18-
if [[ $1 != 2 ]]; then
19-
echo $1
20-
echo "Usage: nginx-vhost.sh username example.com"
21-
exit 4
10+
if [ "$(id -u)" != "0" ]; then
11+
echo "Script must be run as root."
12+
exit 1
2213
fi
2314

24-
egrep "^$USERNAME:" /etc/passwd >/dev/null
25-
if [ $? -eq 0 ]; then
26-
echo "$USERNAME exists!"
27-
exit 3
28-
fi
29-
if [ ! -e /root/mysql ]; then
30-
echo "Root MySQL password file missing. Please run create the file /root/mysql,"
31-
echo "And put your root password as the first and only line."
32-
exit 4
33-
fi
34-
}
35-
36-
function password {
37-
RET=$(cat /dev/urandom | tr -cd [:alnum:] | head -c ${1:-16})
38-
}
39-
40-
function setup_user {
41-
useradd -m -d $USER_DIR/$USERNAME -U $USERNAME
42-
43-
password
44-
PASSWORD=$RET
45-
echo "$USERNAME:$PASSWORD" | chpasswd
46-
47-
mkdir -p $USER_DIR/$USERNAME/$DOMAIN/htdocs
48-
mkdir $USER_DIR/$USERNAME/$DOMAIN/logs
49-
touch $USER_DIR/$USERNAME/$DOMAIN/logs/access.log
50-
touch $USER_DIR/$USERNAME/$DOMAIN/logs/error.log
51-
chown -R $USERNAME $USER_DIR/$USERNAME
52-
chgrp -R $USERNAME $USER_DIR/$USERNAME
53-
54-
echo "Create user: $USERNAME with password: $PASSWORD"
15+
# egrep "^$USERNAME:" /etc/passwd >/dev/null
16+
# if [ $? -eq 0 ]; then
17+
# echo "$USERNAME exists!"
18+
# exit 3
19+
# fi
20+
21+
# if [ ! -e /root/mysql ]; then
22+
# echo "Root MySQL password file missing. Please run create the file /root/mysql,"
23+
# echo "And put your root password as the first and only line."
24+
# exit 4
25+
# fi
5526
}
27+
#
28+
#function password {
29+
# RET=$(cat /dev/urandom | tr -cd [:alnum:] | head -c ${1:-16})
30+
#}
31+
#
32+
#function setup_user {
33+
# useradd -m -d $USER_DIR/$USERNAME -U $USERNAME
34+
#
35+
# password
36+
# PASSWORD=$RET
37+
# echo "$USERNAME:$PASSWORD" | chpasswd
38+
#
39+
# mkdir -p $USER_DIR/$USERNAME/$DOMAIN/htdocs
40+
# mkdir $USER_DIR/$USERNAME/$DOMAIN/logs
41+
# touch $USER_DIR/$USERNAME/$DOMAIN/logs/access.log
42+
# touch $USER_DIR/$USERNAME/$DOMAIN/logs/error.log
43+
# chown -R $USERNAME $USER_DIR/$USERNAME
44+
# chgrp -R $USERNAME $USER_DIR/$USERNAME
45+
#
46+
# echo "Create user: $USERNAME with password: $PASSWORD"
47+
#}
5648
function php_pool {
57-
if [ ! -f /etc/php5/fpm/port ]; then
58-
echo "Cannot access /etc/php5/fpm/port"
59-
exit 2
60-
fi
61-
62-
# Grab the port from file, and increment.
63-
PORT=$(cat /etc/php5/fpm/port)
64-
echo $(($PORT + 1)) > /etc/php5/fpm/port
65-
66-
cp /etc/php5/fpm/pool.template /etc/php5/fpm/pools/$DOMAIN
67-
sed -i "s|example.com|$DOMAIN|" /etc/php5/fpm/pools/$DOMAIN
68-
69-
sed -i "s|PORT|$PORT|" /etc/php5/fpm/pools/$DOMAIN
70-
sed -i "s|user = example|user = $USERNAME|" /etc/php5/fpm/pools/$DOMAIN
71-
sed -i "s|group = example|group = $USERNAME|" /etc/php5/fpm/pools/$DOMAIN
49+
# if [ ! -f /etc/php5/fpm/port ]; then
50+
# echo "Cannot access /etc/php5/fpm/port"
51+
# exit 2
52+
# fi
53+
#
54+
# # Grab the port from file, and increment.
55+
# PORT=$(cat /etc/php5/fpm/port)
56+
# echo $(($PORT + 1)) > /etc/php5/fpm/port
57+
58+
cp pool.template /usr/local/etc/php/5.4/fpm.d/$PROJECT.conf
59+
sed -i.tmp "s|example.com|$DOMAIN|g" /usr/local/etc/php/5.4/fpm.d/$PROJECT.conf
60+
rm /usr/local/etc/php/5.4/fpm.d/$PROJECT.conf.tmp
61+
62+
# sed -i "s|PORT|$PORT|" /usr/local/etc/php/5.4/fpm.d/$DOMAIN
63+
# sed -i "s|user = example|user = $USERNAME|" /usr/local/etc/php/5.4/fpm.d/$DOMAIN
64+
# sed -i "s|group = example|group = $USERNAME|" /usr/local/etc/php/5.4/fpm.d/$DOMAIN
7265
echo "Added $DOMAIN to the PHP pool"
7366
}
67+
7468
function nginx_vhost {
75-
cp /etc/nginx/vhost.template /etc/nginx/sites-available/$DOMAIN
76-
sed -i "s|example.com|$DOMAIN|g" /etc/nginx/sites-available/$DOMAIN
77-
sed -i "s|username|$USERNAME|g" /etc/nginx/sites-available/$DOMAIN
78-
sed -i "s|PORT|$PORT|g" /etc/nginx/sites-available/$DOMAIN
69+
cp vhost.template /usr/local/etc/nginx/sites-available/$DOMAIN
70+
sed -i.tmp "s|example.com|$DOMAIN|g" /usr/local/etc/nginx/sites-available/$DOMAIN
71+
rm /usr/local/etc/nginx/sites-available/$DOMAIN.tmp
72+
# sed -i "s|username|$USERNAME|g" /usr/local/etc/nginx/sites-available/$DOMAIN
73+
# sed -i "s|PORT|$PORT|g" /usr/local/etc/nginx/sites-available/$DOMAIN
7974
# Should probably sed through and replace /ebs/www with $USER_DIR
8075

8176
# Enable the site
82-
ln -s /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/$DOMAIN
83-
echo "Enabled $DOMAIN in the web server"
84-
}
85-
function server_reload {
86-
/etc/init.d/php5-fpm reload
87-
/etc/init.d/nginx reload
88-
echo "Servers reloaded"
89-
}
90-
function prepare_mysql {
91-
# Generate dbuser password
92-
password
93-
DB_PASS=$RET
77+
ln -s /usr/local/etc/nginx/sites-available/$DOMAIN /usr/local/etc/nginx/sites-enabled/$DOMAIN
9478

95-
# Truncate username (15 chars max) and dbname (63 chars max)
96-
USER_TRUNC=$(echo $USERNAME | cut -c1-15)
79+
mkdir "$USER_DIR/projects/$PROJECT"
80+
chown ruscon:staff "$USER_DIR/projects/$PROJECT"
81+
ln -s $USER_DIR/projects/$PROJECT /usr/local/var/www/$DOMAIN
9782

98-
# This should be a separate user with only create perms.
99-
echo "CREATE DATABASE $USER_TRUNC;
100-
GRANT ALL PRIVILEGES ON $USER_TRUNC.* to '$USER_TRUNC'@'localhost' IDENTIFIED BY '$DB_PASS';" > $USERNAME.sql
101-
mysql -u root -p$(cat /root/mysql) < $USERNAME.sql
102-
rm $USERNAME.sql
103-
echo "Created MySQL user: $USER_TRUNC password: $DB_PASS database: $DOMAIN_TRUNC"
104-
}
105-
function add_to_ftp {
106-
usermod -g proftpd $USERNAME
83+
echo "Enabled $DOMAIN in the web server"
10784
}
108-
function install_wordpress {
109-
wget http://wordpress.org/latest.tar.gz
110-
tar xf latest.tar.gz
111-
mv wordpress/* $USER_DIR/$USERNAME/$DOMAIN/htdocs/
112-
cp $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config-sample.php $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
113-
sed -i "s|database_name_here|$USER_TRUNC|g" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
114-
sed -i "s|username_here|$USERNAME|g" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
115-
sed -i "s|password_here|$DB_PASS|g" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
116-
117-
echo " define(\"FTP_HOST\", \"$DOMAIN\");
118-
define(\"FTP_USER\", \"$USERNAME\");
119-
define(\"FTP_PASS\", \"$USERPASS\");" >> $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
120-
121-
# Add in salts from the wordpress salt generator
122-
wget https://api.wordpress.org/secret-key/1.1/salt/
123-
sed -i "s/|/a/g" index.html
124-
# cat index.html | while read line; do
125-
# sed -i "s|define('.*',.*'put your unique phrase here');|$line|" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
126-
# sed 1d $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
127-
# done
128-
sed -i '/#@-/r index.html' $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
129-
sed -i "/#@+/,/#@-/d" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
130-
rm index.html
131-
rm latest.tar.gz
13285

133-
# Add in FTP stuff, even though that's not defined yet..
134-
135-
# Own these new files
136-
chown -R $USERNAME $USER_DIR/$USERNAME/$DOMAIN/htdocs/*
137-
chgrp -R $USERNAME $USER_DIR/$USERNAME/$DOMAIN/htdocs/*
138-
# Make sure no one else can read this file
139-
chmod 700 $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
140-
141-
#echo "Wordpress for $DOMAIN installed."
142-
#echo "Visit http://$DOMAIN/wp-admin/install.php to complete installation"
86+
function ect_host {
87+
echo "127.0.0.1 $DOMAIN" >> /etc/hosts
14388
}
14489

90+
#function server_reload {
91+
# /etc/init.d/php5-fpm reload
92+
# /etc/init.d/nginx reload
93+
# echo "Servers reloaded"
94+
#}
95+
#function prepare_mysql {
96+
# # Generate dbuser password
97+
# password
98+
# DB_PASS=$RET
99+
#
100+
# # Truncate username (15 chars max) and dbname (63 chars max)
101+
# USER_TRUNC=$(echo $USERNAME | cut -c1-15)
102+
#
103+
# # This should be a separate user with only create perms.
104+
# echo "CREATE DATABASE $USER_TRUNC;
105+
#GRANT ALL PRIVILEGES ON $USER_TRUNC.* to '$USER_TRUNC'@'localhost' IDENTIFIED BY '$DB_PASS';" > $USERNAME.sql
106+
# mysql -u root -p$(cat /root/mysql) < $USERNAME.sql
107+
# rm $USERNAME.sql
108+
# echo "Created MySQL user: $USER_TRUNC password: $DB_PASS database: $DOMAIN_TRUNC"
109+
#}
110+
111+
#function add_to_ftp {
112+
# usermod -g proftpd $USERNAME
113+
#}
114+
115+
#function install_wordpress {
116+
# wget http://wordpress.org/latest.tar.gz
117+
# tar xf latest.tar.gz
118+
# mv wordpress/* $USER_DIR/$USERNAME/$DOMAIN/htdocs/
119+
# cp $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config-sample.php $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
120+
# sed -i "s|database_name_here|$USER_TRUNC|g" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
121+
# sed -i "s|username_here|$USERNAME|g" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
122+
# sed -i "s|password_here|$DB_PASS|g" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
123+
#
124+
# echo " define(\"FTP_HOST\", \"$DOMAIN\");
125+
# define(\"FTP_USER\", \"$USERNAME\");
126+
# define(\"FTP_PASS\", \"$USERPASS\");" >> $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
127+
#
128+
# # Add in salts from the wordpress salt generator
129+
# wget https://api.wordpress.org/secret-key/1.1/salt/
130+
# sed -i "s/|/a/g" index.html
131+
## cat index.html | while read line; do
132+
## sed -i "s|define('.*',.*'put your unique phrase here');|$line|" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
133+
## sed 1d $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
134+
## done
135+
# sed -i '/#@-/r index.html' $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
136+
# sed -i "/#@+/,/#@-/d" $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
137+
# rm index.html
138+
# rm latest.tar.gz
139+
#
140+
# # Add in FTP stuff, even though that's not defined yet..
141+
#
142+
# # Own these new files
143+
# chown -R $USERNAME $USER_DIR/$USERNAME/$DOMAIN/htdocs/*
144+
# chgrp -R $USERNAME $USER_DIR/$USERNAME/$DOMAIN/htdocs/*
145+
# # Make sure no one else can read this file
146+
# chmod 700 $USER_DIR/$USERNAME/$DOMAIN/htdocs/wp-config.php
147+
#
148+
# #echo "Wordpress for $DOMAIN installed."
149+
# #echo "Visit http://$DOMAIN/wp-admin/install.php to complete installation"
150+
#}
151+
145152
##############################################################################
146153
# Start of program
147-
USERNAME=$1
148-
DOMAIN=$2
154+
#USERNAME=$1
155+
PROJECT=$1
156+
DOMAIN="$1.dev"
149157

150158
sanity_check $#
151-
setup_user
159+
#setup_user
152160
php_pool
153161
nginx_vhost
154-
server_reload
155-
prepare_mysql
156-
add_to_ftp
157-
install_wordpress
162+
ect_host
163+
#server_reload
164+
#prepare_mysql
165+
#add_to_ftp
166+
#install_wordpress
158167
exit 0

nginx-vhost/pool.template

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# /etc/php5/fpm/pool.template
21
[example.com]
3-
listen = 127.0.0.1:PORT # Increase this for each pool
4-
user = example
5-
group = example
2+
user=ruscon
3+
group=staff
64
pm = dynamic
7-
pm.max_children = 5
8-
pm.start_servers = 1
9-
pm.min_spare_servers = 1
10-
pm.max_spare_servers = 2
5+
pm.max_children = 10
6+
pm.start_servers = 5
7+
pm.min_spare_servers = 5
8+
pm.max_spare_servers = 10
9+
pm.max_requests = 500
10+
;pid = /usr/local/var/run/php5-fpm-example.com.pid
11+
listen = /usr/local/var/run/php5-fpm-example.com.sock
12+
php_flag[display_errors] = on
13+
security.limit_extensions = .php .html .css .js

nginx-vhost/vhost.template

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1-
# /etc/nginx/vhost.template
2-
31
server {
4-
listen 80;
5-
server_name example.com;
6-
access_log /ebs/www/username/example.com/logs/access.log;
7-
error_log /ebs/www/username/example.com/logs/error.log;
8-
root /ebs/www/username/example.com/htdocs;
9-
10-
location / {
11-
index index.php index.html index.htm;
12-
location ~ \.php$ {
13-
fastcgi_pass 127.0.0.1:PORT; # Increase this for each pool
14-
fastcgi_index index.php;
15-
fastcgi_param SCRIPT_FILENAME /ebs/www/username/example.com/htdocs$fastcgi_script_name; # same path as above
16-
fastcgi_param PATH_INFO $fastcgi_script_name;
17-
include /etc/nginx/fastcgi_params;
18-
}
19-
# Static files
20-
if (-f $request_filename) {
21-
expires 30d;
22-
break;
23-
}
24-
if (!-e $request_filename) {
25-
rewrite ^(.+)$ /index.php?q=$1 last;
26-
}
27-
}
28-
}
2+
listen 80;
3+
4+
server_name example.com;
5+
root /usr/local/var/www/example.com;
6+
7+
# error_log /usr/local/var/www/example.com/log/error.log;
8+
# access_log /usr/local/var/www/example.com/log/access.log;
9+
10+
## This should be in your http block and if it is, it's not needed here.
11+
index index.php;
12+
13+
location = /favicon.ico {
14+
log_not_found off;
15+
access_log off;
16+
}
17+
18+
location = /robots.txt {
19+
allow all;
20+
log_not_found off;
21+
access_log off;
22+
}
23+
24+
location / {
25+
#try_files $uri $uri/ /index.php?$args;
26+
try_files $uri $uri/ /index.php;
27+
}
28+
29+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
30+
location ~ \.php$ {
31+
fastcgi_pass unix:/usr/local/var/run/php5-fpm-example.com.sock;
32+
fastcgi_intercept_errors on;
33+
include fastcgi_params;
34+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
35+
fastcgi_param HTTPS off;
36+
}
37+
38+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
39+
expires max;
40+
log_not_found off;
41+
}
42+
}

0 commit comments

Comments
 (0)