LNMP(動態網站)

LNMP(動態網站)
nginx(靜態網站)

案例1:部署LNMP環境
步驟一:安裝軟件
yum -y install mariadb mariadb-server
yum -y install mariadb-devel
yum -y install php php-mysql
cd lnmp_soft
rpm -ivh php-fpm-5.4.16-36.el7_1.x86_64.rpm

啓動服務
nginx
systemctl start php-fpm
systemctl start mariadb

LNMP

nginx----PHP(動靜分離)
nginx判斷用戶訪問的是靜態還是動態
如果是靜態,則在root對應的目錄中找到頁面直接給用戶
如果是動態,則nginx將請求轉發給9000端口
location匹配用戶的地址欄(支持正則)
eg server {
listen 80;
server_name localhost;
location / {
root html;
}
location ~ .php$ {
pass 127.0.0.1:9000;
}
}
案例2:構建LNMP平臺
vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
/usr/local/nginx/sbin/nginx -s reload

創建PHP頁面,測試LNMP架構能否解析PHP頁面

1)創建PHP測試頁面1:
[root@svr5 ~]# vim /usr/local/nginx/html/test1.php
<?php
$i="This is a test Page";
echo $i;
?>

http://192.168.4.5/test1.php
常見錯誤
File not found:沒有權限
ls,權限【rwx,selinux,acl】
Connection refused:PHP沒有啓動
PHP Parse error:syntax error
PHP語法錯誤
location 下載頁面

拷貝mysql模板
cd /root/lnmp_soft/php_scripts/
ls
cp mysql.php /usr/local/nginx/html/

地址重寫
www.360buy.com ----> www.jd.com
格式:rewrite 舊地址 新地址 【選項】
last [地址變,不讀其他rewrite]
break [地址變,不讀其他語句,訪問結束]
redirect [地址變]臨時重定向
permament [地址變]永久重定向
支持正則
rewrite /a.html /b.html redirect;

修改Nginx服務配置
vim /usr/local/nginx/conf/nginx.conf
root html;
index index.html index.htm;(增加此行)
}
echo "B是大寫的B" > /usr/local/nginx/html/b.html
訪問192.168.4.5/a.html

rewrite ^/ http://www.tmooc.cn/;

使用uc訪問是窄屏頁面
使用ie訪問是寬屏頁面
mkdir /usr/local/nginx/htmlcurl
建立2個名字相同的網頁
vim /usr/local/nginx/html/test.html
vim /usr/local/nginx/html/curl/test.html

vim /usr/local/nginx/conf/nginx.conf

if ($http_user_agent ~ curl){ //識別客戶端curl瀏覽器
rewrite ^(.
)$ /curl/$1;
}
#發現包含curl的就訪問curl/
nginx -s reload
驗證
curl http://192.168.4.5/test.html
firefox http://192.168.4.5/test.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章