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的配置使用

相關文章
相關標籤/搜索