LNMP架构(二)

五 Nginx安装

cd /usr/local/src

下载wget http://nginx.org/download/nginx-1.12.1.tar.gz

解压tar zxf nginx-1.12.1.tar.gz

编译 ./configure --prefix=/usr/local/nginx

安装make && make install

vim /etc/init.d/nginx //复制如下内容

#!/bin/bash

# chkconfig: - 30 21

# description: http service.

# Source Function Library

. /etc/init.d/functions

# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"

NGINX_CONF="/usr/local/nginx/conf/nginx.conf"

NGINX_PID="/usr/local/nginx/logs/nginx.pid"

RETVAL=0

prog="Nginx"

start()

{

echo -n $"Starting $prog: "

mkdir -p /dev/shm/nginx_temp

daemon $NGINX_SBIN -c $NGINX_CONF

RETVAL=$?

echo

return $RETVAL

}

stop()

{

echo -n $"Stopping $prog: "

killproc -p $NGINX_PID $NGINX_SBIN -TERM

rm -rf /dev/shm/nginx_temp

RETVAL=$?

echo

return $RETVAL

}

reload()

{

echo -n $"Reloading $prog: "

killproc -p $NGINX_PID $NGINX_SBIN -HUP

RETVAL=$?

echo

return $RETVAL

}

restart()

{

stop

start

}

configtest()

{

$NGINX_SBIN -c $NGINX_CONF -t

return 0

}

case "$1" in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

restart

;;

configtest)

configtest

;;

*)

echo $"Usage: $0 {start|stop|reload|restart|configtest}"

RETVAL=1

esac

exit $RETVAL

chmod 755 /etc/init.d/nginx

chkconfig --add nginx

chkconfig nginx on

cd /usr/local/nginx/conf/;

mv nginx.conf nginx.conf.bak

vim nginx.conf //写入如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf)

/usr/local/nginx/sbin/nginx -t

/etc/init.d/nginx start

netstat -lntp |grep 80

测试Nginx:curl 127.0.0.1或者curl localhost访问

测试PHP解析

vi /usr/local/nginx/html/1.php //加入如下内容

<?php

echo "test php scripts.";

?>

curl localhost/1.php

六 Nginx默认虚拟主机

第一个被Nginx加载的虚拟主机就是默认主机。和httpd不同的是,它有一个配置用来标记默认虚拟主机,也就是说,如果没有这个标记,第一个虚拟主机为默认虚拟主机。

vim /usr/local/nginx/conf/nginx.conf //增加

include vhost/*.conf

mkdir /usr/local/nginx/conf/vhost

cd !$; vim default.conf //加入如下内容

server

{

listen 80 default_server; // 有这个标记的就是默认虚拟主机

server_name aaa.com;

index index.html index.htm index.php;

root /data/wwwroot/default;

}

mkdir -p /data/wwwroot/default/

echo "This is a default site.">/data/wwwroot/default/index.html

/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx -s reload

curl localhost

curl -x127.0.0.1:80 aaa.com

七 Nginx用户认证

vim /usr/local/nginx/conf/vhost/test.com.conf//写入如下内容

server

{

listen 80;

server_name test.com;

index index.html index.htm index.php;

root /data/wwwroot/test.com;

 

location /

{

auth_basic "Auth";

auth_basic_user_file /usr/local/nginx/conf/htpasswd;

}

}

yum install -y httpd

htpasswd -c /usr/local/nginx/conf/htpasswd aming

-t && -s reload //测试配置并重新加载

401说明网站需要验证

针对某个目录做用户认证,需要修改location后面的路径

server

{

listen 80;

server_name test.com;

index index.html index.htm index.php;

root /data/wwwroot/test.com;

 

location /admin/

{

auth_basic "Auth";

auth_basic_user_file /usr/local/nginx/conf/htpasswd;

}

}

针对访问的url

server

{

listen 80;

server_name test.com;

index index.html index.htm index.php;

root /data/wwwroot/test.com;

 

location /admin/

{

auth_basic "Auth";

auth_basic_user_file /usr/local/nginx/conf/htpasswd;

}

}

八 Nginx域名重定向

更改test.com.conf

server

{

listen 80;

server_name test.com test1.com test2.com;

index index.html index.htm index.php;

root /data/wwwroot/test.com;

if ($host != 'test.com' ) {

rewrite ^/(.*)$ http://test.com/$1 permanent;

}

}

server_name后面支持写多个域名,这里要和httpd的做一个对比

permanent为永久重定向,状态码为301,如果写redirect则为302

[root@greg02 vhost]#/usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@greg02 vhost]#/usr/local/nginx/sbin/nginx -s reload

[root@greg02 vhost]#curl -x127.0.0.1:80 test2.com/index.html -I

HTTP/1.1 301 Moved Permanently

Server: nginx/1.12.2

Date: Sat, 11 Nov 2017 11:14:43 GMT

Content-Type: text/html

Content-Length: 185

Connection: keep-alive

Location: http://test.com/index.html

乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值