Nginx基础(访问控制、虚拟主机、LAMP)

Nginx基础(访问控制、虚拟主机、LAMP)

1.Nginx的优点php

    高并发链接html

    内存消耗少mysql

    成本低廉nginx

    内置监控检查功能web

    支持热部署sql

2.应用vim

1.运行PHP、JSP、centos

2.反向代理、负载均衡浏览器

3.运行HTML、图片缓存

4.Nginx和cache插件实现对web服务器缓存功能

3.安装

[root@localhost ~]# yum install -y http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.12.1-1.el7.ngx.x86_64.rpm

[root@localhost ~]# rpm -ql nginx | less        //查看

[root@localhost ~]# systemctl start nginx       //启动

[root@localhost ~]# systemctl enable nginx      //开机自启

[root@localhost ~]# netstat -an | grep :80      //监听80端口(不能和Apache同时安装,会致使端口冲突)

[root@localhost ~]# curl http://localhost       //访问

[root@localhost ~]# nginx –v            //查看版本

[root@localhost ~]# nginx –t            //检查语法

[root@localhost ~]# nginx –V            //查看具体信息

4.Nginx安装第三方模块

--add model

5.nginx的配置文件及添加功能

[root@localhost ~]# vim /etc/nginx/nginx.d.default.conf

1.启用统计页面

blob.png

重启;访问http://192.168.122.22 f5强制刷新后便可看到改变

6.nginx自动列出目录配置(虚拟目录)

[root@localhost ~]# cd /usr/share/nginx/html/

[root@localhost html]# touch soft/file{1..5}.doc

[root@localhost conf.d]# vim /etc/nginx/conf.d/default.conf

blob.png

重启----浏览器检测:http://192.168.122.22/soft

7.Nginx浏览器本地缓存设置

使用expires指令输出Header头实现

[root@localhost conf.d]# vim /etc/nginx/conf.d/default.conf

blob.png

8.虚拟主机

1.基于不一样的ip

2.基于不一样的端口

3.基于主机名的不一样

    修改hosts文件,写一个临时的域名解析

9.Nginx访问控制

1.基于地址的访问控制(限制某一个主机)

    仅容许192.168.122.21访问(配置段:http、server、location)

    [root@localhost html]# vim /etc/nginx/conf.d/default.confblob.png

  重启服务:

  [root@localhost ~]# systemctl restart nginx

  容许网段192.168.122.0访问,但不容许192.168.122.21访问blob.png


2.基于用户的访问控制(对于实现访问网站或目录密码认证保护)

 1.添加认证指令

[root@localhost ~]# vim /etc/nginx/conf.d/default.conf

blob.png

  2.建立密码文件,加密密码

[root@localhost ~]# yum install httpd-tools –y

[root@localhost ~]# htpasswd -c -b /data/web2/webpass user1 123456

[root@localhost ~]# htpasswd  -b /data/web2/webpass user2 user2

  3.重启

[root@localhost ~]# systemctl restart nginx

  4.测试

[root@localhost ~]# yum install -y elinks

[root@localhost ~]# elinks http://192.168.122.22

blob.png

10.LNMP的搭建

[root@localhost ~]# yum install -y mariadb-server mariadb

[root@localhost ~]# systemctl start mariadb

[root@localhost ~]# mysql_secure_installation    //设置密码

[root@localhost ~]# yum install -y php-fpm php-mysql php

[root@localhost ~]# vim /etc/nginx/conf.d/default.con

blob.png

将fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;修改成fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

[root@localhost ~]# vim /etc/php.ini

将;cgi.fix_pathinfo=1 改成cgi.fix_pathinfo=0

将时区修改:date.timezone=Asia/Shanghai

[root@localhost ~]# systemctl restart nginx php-fpm

测试:写一个phpinfo.php文件进行测试便可

相关文章
相关标签/搜索