xx

[root@localhost ~]# mkdir/var/www/html/test/php

[root@localhost ~]# firewall-cmd--set-default-zone=trustedhtml

[root@localhost ~]# setenforce 0mysql

[root@localhost ~]# yum install httpd -ylinux

[root@localhost ~]# systemctl start httpdnginx

 

对一个uri进行验证web

[root@localhost ~]# echo '******Test******'> /var/www/html/test/index.html正则表达式

[root@localhost ~]# vim/etc/httpd/conf/httpd.conf  #  配置文件目录sql

<Directory"/var/www/html/test">数据库

    Options Indexes FollowSymLinksapache

    AllowOverride AuthConfig

    Require all granted

</Directory>

[root@localhost ~]# vim/var/www/html/test/.htaccess

AuthName"ss"

AuthType"Basic"

AuthUserFile"/etc/httpd/conf/.htpasswd"

Requireuser "tom"

[root@localhost ~]# htpasswd -cm /etc/httpd/conf/.htpasswdtom  # 在AuthUserFile指定的文件路径建立密码文件

[root@localhost ~]# htpasswd -m/etc/httpd/conf/.htpasswd tom  # 修改用户密码 

[root@localhost ~]# htpasswd -D/etc/httpd/conf/.htpasswd tom  删除用户

spacer.gif

spacer.gif

apache的FollowSymLinks参数

spacer.gif

spacer.gif

 

 

Alias参数

spacer.gif

spacer.gif

 

 

 

当client发送一个请求给web服务时,web会在服务端执行这脚本而且将执行的结果返还给client。

 

apache中Rewrite对URI的重写规则

spacer.gif

 

rewrite语法的格式
开启重写功能

RewriteEngineon

RewriteRule是对URI进行重写

RewriteRule模式1 模式2 [标签]

模式中都支持正则表达式

模式1:原来的

模式2:替换后的

[R]:强制地址重写

[F]:禁用URL,返回403错误

[L]:后面就没有规则了,我就是最后一条,后面即便有规则也不生效

[N]:表示从第一条规则从新分析

[C]:结合下一条规则一块儿使用

 

spacer.gif

spacer.gif

spacer.gif

 

 

 

对url的重写

spacer.gif

 

 

spacer.gif

 

 

若是没有对httpd.conf配置文件的权限,可使用.htaccess来修改某个目录的属性

想修改哪一个目录的属性,就在哪一个目录里建立一个.htaccess文件这样子能覆盖/etc/htttpd/httpd.conf文件的设置,在httpd.conf里面所设置的都能一个文档目录中的.htaccess文件中来设置

spacer.gif

 

 

 

nginx的配置

[root@nginx ~]# firewall-cmd --set-default-zone=trusted

[root@nginx ~]# setenforce 0

 

nginx安装与使用
yum源的配置

[nginx]

name=nginxrepo

baseurl=http://nginx.org/packages/rhel/7/$basearch/

gpgcheck=0

enabled=1
[root@nginx ~]# yum install nginx -y

[root@nginx ~]# ls -al/usr/share/nginx/html/  # nginx的文档目录

 

若是http_user_agent ~ QQBrowser则重定向到/qq/index.html,若是不匹配则拒绝192.168.30.1访问

 

 

选项必须以分号结束,选项没有出如今server中则会影响全部的server,若是server中出现的选项则以server中的选项生效

 

有多个虚拟机主机写多个server {

 

全局性配置

--------------

--------------

http{

       选项1;

       选项2;

            server {

                 location 匹配 条件 {   # 对于URI进行设置

spacer.gif                      # =  严格匹配

                      # location =/exam/ {

#                   }      

#  ~  能够写正则,可是大小写区分     

#  ~* 和上面意思同样,可是忽略大小写

在location里是能够写if判断的,格式:

#                         if (判断) {

#                           语句1;

#                                   }

                                     }

                 

           

            server {

            

                 

     }

 

[root@nginx ~]# cat /etc/nginx/nginx.conf  #  nginx主配置文件

user nginx;

worker_processes  1;

error_log /var/log/nginx/error.log warn;

pid       /var/run/nginx.pid;

 

events {

   worker_connections  1024;

}

http {

   include      /etc/nginx/mime.types;  # 传时所支持的文件类型

default_type  application/octet-stream;

# 日志的格式引用变量进行输出

   log_format  main  '$remote_addr - $remote_user [$time_local]"$request" '

                      '$status $body_bytes_sent"$http_referer" '

                     '"$http_user_agent" "$http_x_forwarded_for"';

#1.84.81.232 - - [11/Mar/2017:02:48:51 -0500] "GET /yer/code/ncloginHTTP/1.1" 200 1399 #"http://bx.elegantliving.cn/yer/core/login/login.jsp""Mozilla/5.0 (Windows NT 10.0; Win64; #x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/51.0.27:

access_log  /var/log/nginx/access.log  main;  # 全部的虚拟主机产生的日志都记录在一个日志文件中,若是想让不一样的虚拟主机的所产生的日志都记录在不一样的日志文件中

在,注释nginx.conf文件中的日志行而后在/etc/nginx/conf.d目录中的配置文定义曲线部分

server {

   listen       80;

   server_name  localhost;

   #charset koi8-r;

   #access_log  /var/log/nginx/log/host.access.log  main;

   location / {

        root  /usr/share/nginx/html;

        index index.html index.htm;

}   

sendfile        on;

   #tcp_nopush     on;

   keepalive_timeout  65;

   #gzip  on;

   include /etc/nginx/conf.d/*.conf;

}

 

[root@nginx ~]# vim/etc/nginx/conf.d/default.conf # 目录下配置文件讲解

server {

   listen       80;

   server_name  192.168.5.90;

   charset utf-8;

   access_log /var/log/nginx/nginx.access.log main;

   location / {   # 至关于apache中的Directory用于对目录的权限设置等

       root   /usr/share/nginx/html;

       index  index.html index.php;

    }

   error_page   500 502 503 504  /50x.html;

   location = /50x.html {

       root   /usr/share/nginx/html;

    }

}

 

加不加/index.html访问的效果都是同样的但由是location的匹配规则:

spacer.gif

spacer.gif

spacer.gif

spacer.gif

spacer.gif

spacer.gif

break至关于apache重写规则中的标签[R]

spacer.gif

spacer.gif

spacer.gif

多虚拟主机配置

 

spacer.gif

spacer.gif

 

spacer.gif

 

discuz论坛的搭建

 

数据库的安装配置

[root@nginx ~]# yum install mariadb-serverphp\* -y

[root@nginx ~]# systemctl start mariadb ;systemctl enable  mariadb

[root@nginx ~]# mysql -uroot

MariaDB [(none)]> create databaseDiscuz;

MariaDB [(none)]> grant all on Discuz.*to Discuz@'localhost' identified by 'Discuz' ;

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> \q

 

上传discuz论坛网页文件

到http://www.discuz.net/forum-10-1.html下载Discuz_X3.3_SC_UTF8.zip

解压得以下文件夹

spacer.gif

将upload里面的文件上传到nginx文档目录中

spacer.gif

 

编辑nginx配置文件

spacer.gif

 

 

运行php环境

spacer.gif

spacer.gif

 

 

Discuz初始化设置

spacer.gif

spacer.gif

spacer.gif

 

spacer.gif

spacer.gif

 

在nginx上配置ssl

spacer.gif

 

生成密钥对,密钥对须要pem格式的否则重启服务后会报错

spacer.gif

spacer.gif

spacer.gif

spacer.gif

 

 

 

 

 

若是访问的主页不存在则会显示网页的目录,

spacer.gif

 

autoindex on至关于apache中的Options Indexes FollowSymLinks。

spacer.gif

 

 

 

 

 

nginx的负载均衡

访问网站的时候为了提升网站的速度须要配置代理服务器

 

代理服务器---在客户端设置

为了提升客户端访问的速度,当客户端访问某个页面的时候首先会把请求发给代理服务器,代理服务器收到客户端发送的这个请求会在本身的本地查看是否有这个页面,若是有的话则会将这个页面发送给客户端,若是没有代理服务器则会向真实服务器发送请求而且将这个页面缓存下来。

spacer.gif

反向代理---在服务器设置

 

 

环境的准备

spacer.gif

spacer.gif
spacer.gif

 

 

spacer.gif

spacer.gif

 

[root@nginx ~]# sysctl -wnet.ipv4.ip_forward=1  # 开启ip转发功能

 

[root@s1 ~]# firewall-cmd--set-default-zone=trusted #nginx、s2一样不考虑防火墙

root@s1 ~]# setenforce 0  #  nginx、s2一样不考虑selinux

 

[root@s1 ~]# sed -i '$aGATEWAY=192.168.122.1' /etc/sysconfig/network-scripts/ifcfg-eth0

[root@s1 ~]# systemctl restart network  # 将s2的网关也设置为192.168.122.1

 

[root@s1 ~]# yum install httpd -y # s2也安装

[root@s1 ~]# echo 'xxxx' >/var/www/html/index.html

[root@s2 ~]# echo 'yyyy' >/var/www/html/index.html

 

[root@nginx ~]# egrep -v '(^*#|^$)'/etc/nginx/nginx.conf

user  nginx;

worker_processes  1;

error_log  /var/log/nginx/error.log warn;

pid        /var/run/nginx.pid;

events{

    worker_connections  1024;

}

http{

    upstream myapp1 {

        server 192.168.122.31;

        server 192.168.122.32;

    }

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    log_format main  '$remote_addr - $remote_user[$time_local] "$request" '

                      '$status $body_bytes_sent"$http_referer" '

                     '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;

}

[root@nginx ~]# egrep -v '(^*#|^$)'/etc/nginx/conf.d/default.conf

server{

        listen 80;

        location / {

            proxy_pass http://myapp1;

        }

    }

 

Squid的配置使用

相关文章
相关标签/搜索