#Linux阶段学习重点
1.Linux常用命令
2.Linux系统管理
3.Linux网络应用
4.LAMP产品级环境搭建
5.Apache服务器配置
6.LNMP环境快速部署-Nginx服务器配置
##目标
1.具有使用Linux系统进行开发的能力
2.进行Linux服务器常规管理运维
##第六天 LNMP环境快速部署-Nginx服务器配置
###一.LNMP环境快速部署
1.系统Linux准备 恢复快照 初始化安装
设置IP 关闭防火墙 配置yum源
2.传输软件包
3.部署步骤:1) tar -zxvf lnmp1.2-full.tar.gz
2) cd lnmp1.2-full
3) ./install.sh lnmp
###二. nginx、MySQL、PHP相关目录以及配置文件
服务管理
lnmp start | stop | restart | status | reload | kill
lnmp nginx start | stop | restart | status | reload | kill
###三. 配置文件
vim /usr/local/nginx/conf/nginx.conf
####实验1 虚拟主机
1.域名解析
192.168.184.252 www.sina.com
192.168.184.252 www.sohu.com
2.网站目录规划
mkdir /home/wwwroot/sina/
mkdir /home/wwwroot/sohu/
vim /home/wwwroot/sina/index.html
vim /home/wwwroot/sohu/index.html
3.修改配置文件
vim /usr/local/nginx/conf/nginx.conf
66 listen 80;
4. 建立虚拟主机文件
vim /usr/local/nginx/conf/vhost/v.conf
server {
listen 80;
server_name www.sina.com;
index index.html index.htm index.php;
root /home/wwwroot/sina/;
include enable-php.conf;
}
server {
listen 80;
server_name www.sohu.com;
index index.html index.htm index.php;
root /home/wwwroot/sohu/;
include enable-php.conf;
}
5.重启服务 测试
pkill -HUP nginx
www.sina.com www.sohu.com
####实验2 rewrite 重写/重定向
www.sina.com -> www.sohu.com
1.修改配置文件
vim /usr/local/nginx/conf/vhost/v.conf
server {
listen 80;
server_name www.sina.com;
index index.html index.htm index.php;
root /home/wwwroot/sina/;
include enable-php.conf;
location /nginx_status{
stub_status on;
access_log off;
}
if ($http_host = www.sina.com) {
rewrite (.*) http://www.sohu.com permanent;
}
}
2. 重启服务 测试
pkill -HUP nginx
测试 www.sina.com -> www.sohu.com
网页文件跳转
1.修改配置文件
server {
listen 80;
server_name www.sina.com;
index index.html index.htm index.php;
root /home/wwwroot/sina/;
include enable-php.conf;
location /nginx_status{
stub_status on;
access_log off;
}
rewrite index(\d+).html /index.php?id=$1 last;
}
2.建立 index.php文件
vim /home/wwwroot/sina/index.php
<?php echo "hello rewrite"; ?>
3.重启服务 测试
pkill -HUP nginx
测试 www.sina.com/index5.html
####实验3 代理负载均衡(反向代理)
准备工作: S 192.168.184.252 Nginx
S1 192.168.184.122 LAMP
S2 192.168.184.146 LAMP
C 测试
www.sohu.com
1.配置S 192.168.184.252 Nginx
vim /usr/local/nginx/conf/nginx.conf
upstream myweb1 {
server 192.168.184.122:80;
server 192.168.184.146:80;
}
server {
listen 80;
server_name www.sohu.com;
location / {
proxy_pass http://myweb1;
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
2.配置S1 192.168.184.122 正常访问 关闭虚拟主机
vim /usr/local/apache2/htdocs/index.html
S111111111111
sto
sta
测试:192.168.184.122
3.配置S2 192.168.184.146 正常访问 关闭虚拟主机
vim /usr/local/apache2/htdocs/index.html
S2222222222222
sto
sta
测试:192.168.184.146
4.重启S 服务 测试
pkill -HUP nginx
测试 www.sohu.com
###作业
所有实验 至少三遍