#####################
---LNMP
企業主流的網站平臺
L --> Linux系統
N --> Nginx網站服務軟件
M --> Mariadb數據庫
P --> Php網站開發語言
#####################
---LNMP環境搭建
(1)安裝Nginx 端口:80
nginx軟件包不在光盤內,需源碼包編譯安裝
安裝依賴軟件包
yum -y install gcc openssl-devel(支持https) pcre-devel(支持正則表達式)
tar xf nginx-1.8.0....
cd nginx-1.8.0
./configure \
--prefix=/usr/local/nginx \ //指定安裝目錄
--with-http_ssl_module //增加安全模塊
make //編譯
make install //安裝
ln -s /usr/local/nginx/sbin/nginx /usr/sbin //製作快捷方式
ls /usr/local/nginx
logs :日至文件
sbin :程序文件
conf :配置文件
html :網頁文件
nginx //啓動服務
nginx -s stop //停止服務
nginx -s reload //重新加載配置文件
nginx -V //查看nginx信息
#####################################
安裝php軟件包 端口:9000
yum -y install php php-mysql(實現php與數據庫連接)
rpm -ivh php-fpm....
/etc/php-fpm/www
####################################
安裝mariadb軟件包 端口:3306
yum -y install mariadb mariadb-server mariadb-devel
###################################
啓動LNMP 環境
nginx
systemctl restart mariadb
systemctl restart php-fpm
##################################
---製作動靜分離頁面
【LNMP】
vim test.php
<?php
$i=33;
$j=44'
echo $i;
?>
php test.php
33
mv test.php /usr/local/nginx/html
【客戶端】
firefox 192.168.4.5/test.php
//需要下載,並且看到的只是源代碼
//這是所謂的靜態頁面
所謂的動態頁面,即把源代碼經過解釋後,顯示到屏幕上的內容
爲了讓客戶端能夠讀到靜態頁面和動態頁面,需要在nginx上進行區分
【LNMP】
/usr/local/nginx/conf/nginx.conf
http {
server {
listen 80;
server_name localhost;
location / {
root html
index index.html index.htm; //對應靜態頁面
}
location ~\.php$ {
root html
fasticgi_pass 127.0.0.1:9000;
fasticgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf; //對應動態頁面
}
}
}
nginx -s reload
【客戶端】
firefox 192.168.4.5/test.php
33
File not found. 出現這個 表示selinux 限制 test.php 沒有安全上下文(標籤)selinux 改成premissive
##########################################
---地址重寫
意義: 換ip地址後,對於一些用戶將無法訪問,使用地址重寫,即把訪問老地址 轉換成新地址
如:訪問 www.360.com -->www.so.com
(1)訪問此網站的內容跳轉到新的內容
【LNMP】
http {
server {
listen 80;
server_name localhost;
location / {
root html
index index.html
rewrite /a\.html /b\.html //因爲支持正則,.代表匹配任意單個字符,所以屏蔽特殊字符
}
}
}
echo "aaaa" > /usr/local/nginx/html/a.html
echo "bbbb" > /usr/local/nginx/html/b.html
【客戶端】
firefox 192.168.4.5/a.html
bbbb
(2)訪問此網站跳轉到別的網站
http {
server {
listen 80;
server_name localhost;
rewrite ^/(.*) http://www.tmooc.cn/$1; // 匹配到 / 時 跳轉到 http://www.tmooc.cn/ 網站中
// (.*)是把/後面的保存起來 $1粘貼 正則中爲 \1
location / {
root html;
index index.html;
#rewrite /a\.html /b\.html;
}
}
}
【客戶端】
firefox 192.168.4.5/yyyy ---> www.tmooc.cn/yyyy
(3)區分瀏覽器或者是不同設備 讓電腦端(手機端)顯示相同內容,格式不同
http {
server {
listen 80;
server_name localhost;
if ($http_user_agent ~* firefox) {
rewrite ^/(.*) /firefox/$1;
}
//$http_user_agent 日至消息中的一段,其中包含firefox等瀏覽器信息,匹配到此瀏覽器後跳轉到其網頁中
#rewrite ^/(.*) http://www.tmooc.cn/$1; // 匹配到 / 時 跳轉到 http://www.tmooc.cn/ 網站中
// (.*)是把/後面的保存起來 $1粘貼 正則中爲 \1
location / {
root html;
index index.html;
#rewrite /a\.html /b\.html;
}
}
}
mkdir /usr/local/nginx/html/firefox
echo "firefox" > /usr/local/nginx/html/firefox/test.html
echo "chrome" > /usr/local/nginx/html/test.html
【客戶端】
firefox 192.168.4.5/test.html //使用火狐瀏覽器
firefox
curl 192.168.4.5/test.html //使用curl 瀏覽器
chrome
在實際網站中 兩個訪問的內容相同,格式不同
###########################################################