Linux基础(六)-Nginx服务

#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

###作业

	所有实验 至少三遍 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值