Configure apache
Build a LAMP environment
Configure the LAMP environment.
Sudo apt-get install tasksel
Sudo tasksel
After entering the preceding command, you can directly select LAMP. During installation, you will be asked to enter the mysql root user password.
Modify apache configuration
Edit the apache configuration file and change it to the following format.
Root @ lylinux :~ # Cat/etc/apache2/ports. conf
# If you just change the port or add more ports here, you will likely also
# Have to change the VirtualHost statement in
#/Etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (I. e. from
# Debian etch). See/usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz
Namevirtualhost*: 8080
Listen 8080.
# If you add NameVirtualHost *: 443 here, you will also have to change
# The VirtualHost statement in/etc/apache2/sites-available/default-ssl
#
# Server Name Indication for SSL named virtual hosts is currently not
# Supported by MSIE on Windows XP.
Listen 443.
Listen 443.
Modify the/etc/apache2/sites-enabled/000-default file at the same time. Only modify the port number.
Root @ lylinux :~ # Cat/etc/apache2/sites-enabled/000-default
ServerAdmin webmaster @ localhost
......
......
Since nginx is used as the front-end, KeepAlive in the apache configuration file can be disabled. Modify/etc/apache2/apache2.conf and set KeepAlive to Off.
KeepAlive Off
Disable useless modules.
A2dismod deflate
A2dismod cgi
A2dismod autoindex
A2dismod negotiation
A2dismod ssl
Install the rpaf module. Otherwise, the source address recorded in the apache log file is 127.0.0.1.
Apt-get install libapache2-mod-rpaf
Restart apache
Service apache2 restart
Install nginx
Apt-get install nginx
Configure nginx
Delete unused configurations
Rm-rf/etc/nginx/sites-enabled /*
Create a new default VM configuration
Cat>/etc/nginx/sites-available/000-default <EOF
Server {
Access_log off;
Location /{
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_set_header Host $ host;
Proxy_pass http: // 127.0.0.1: 8080;
}
}
EOF
Ln-s/etc/nginx/sites-available/000-default/etc/nginx/sites-enabled/000-default
Create a VM and use apache as the backend.
Cat>/etc/nginx/sites-available/domain.com <EOF
Server {
Server_name www.domain.com domain.com;
Root/var/www/domain.com /;
Access_log off;
# Static contents
Location ~ * ^. +. (Jpg | jpeg | gif | png | ico | css | zip | tgz | gz | rar | bz2 | doc | xls | exe | pdf | ppt | txt | tar | mid | midi | wav | bmp | rtf | js) $ {
Expires max;
}
# Dynamic content, forward to Apache
Location /{
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_set_header Host $ host;
Proxy_pass http: // 127.0.0.1: 8080;
}
}
EOF
Ln-s/etc/nginx/sites-available/domain.com/etc/nginx/sites-enabled/domain.com
Restart nginx
/Etc/init. d/nginx restart
Optimization
Finally, we will make some optimizations to apache and mysql.
Apache optimization
Sed-I-e "s/^ [[: blank:] * StartServers [[: blank:] *. */StartServers 5/"/etc/apache2/apache2.conf
Sed-I-e "s/^ [[: blank:] * MinSpareServers [[: blank:] *. */MinSpareServers 5/"/etc/apache2/apache2.conf
Sed-I-e "s/^ [[: blank:] * MaxSpareServers [[: blank:] *. */MaxSpareServers 10/"/etc/apache2/apache2.conf
Sed-I-e "s/^ [[: blank:] * ServerLimit [[: blank:] *. */ServerLimit 10/"/etc/apache2/apache2.conf
Sed-I-e "s/^ [[: blank:] * MaxClients [[: blank:] *. */MaxClients 10/"/etc/apache2/apache2.conf
Sed-I-e "s/^ [[: blank:] * MinSpareThreads [[: blank:] *. */MinSpareThreads 5/"/etc/apache2/apache2.conf
Sed-I-e "s/^ [[: blank:] * MaxSpareThreads [[: blank:] *. */MaxSpareThreads 10/"/etc/apache2/apache2.conf
Mysql optimization
Cp/etc/mysql/my. cnf/etc/mysql/my. cnf. 'Date + % s'
Find/usr/share/doc/mysql *-name my-small.cnf-exec cp {}/etc/mysql/my. cnf \;
Sed-I's/\ [mysqld \]/& \ nuser = mysql \ n/'/etc/mysql/my. cnf