總項目流程圖,詳見 http://www.cnblogs.com/along21/p/8000812.html
實戰一:搭建lnmp及類小米等商業網站的實現
1、安裝包,開啟服務
yum -y install nginx mariadb-server php-fpm php-mysql
2、修改nginx的配置文件
(1)cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf 有個模板例子覆蓋了配置文件
vim /etc/nginx/nginx.conf 修改下面幾類
① user nobody; 使用用戶 error_log /var/log/nginx/error.log info; 錯誤日志 ② events { worker_connections 65535; } ③ tcp_nopush on; tcp優化 tcp_nodelay on; gzip on; ④ server { listen 80; server_name xiaomi.along.com; 根據自己順便寫 root /data/web; 主站點的目錄根 location / { index index.php index.html index.htm; } ⑤ location ~ \.php$ { 開啟.php,配置文件有例子,只需去掉注釋,修改一行即可 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
systemctl restart nginx 重啟服務,發現有warn
(3)ulimit -n 查看linux系統里打開文件描述符的最大值,一般缺省值是1024,對一台繁忙的服務器來說,這個值偏小,所以有必要重新設置linux系統里打開文件描述符的最大值
3、修改php-fpm的配置文件
date.timezone = Asia/Shanghai 時區
② vim /etc/php-fpm.d/www.conf 改兩行
4、運行mysql ,創建一會網頁需要的庫
5、把事先找好的小米網站傳進來 rz
小米網站的源碼資源我已經上傳到網盤了http://pan.baidu.com/s/1kUUFp6B ,需要的可以打賞博主一杯咖啡錢,然后私密博主,博主會很快答復的~
mkdir /data/web -p 創建一個目錄專門放小米的網頁配置
unzip -d /data/web/ xiaomi.zip 解壓到目錄
chown -R nobody.nobody * 為了安全,遞歸把所有文件的所屬人和所屬組改為權限有限的nobody
6、網頁登錄
7、實驗成功,登錄查看
ab -c 100 -n 1000 http://192.168.30.107/
實驗二:實現ssl 加密
1、創建存放證書的目錄
2、自簽名證書
openssl rsa -in nginx.key -out nginx2.key 因為剛私鑰被加密了,為了后邊方便,解密
3、把證書和私鑰cp 到nginx存放證書目錄
cp nginx.crt nginx2.key /etc/nginx/ssl/
mv nginx2.key nginx.key 把名字改回來
4、修改配置文件,加一段server
server { listen 443 ssl; server_name www.along.com; ssl on; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; ssl_session_cache shared:sslcache:20m; ssl_session_timeout 10m; }
5、測試,網頁打開 https://192.168.30.7/
(2)因為nginx 強大,可以實現多個虛擬主機基於不同的FQDN 實現ssl加密,httpd不能實現
2、把證書和私鑰cp 到nginx存放證書目錄,並解開私鑰的加密
cp nginx{1,2,3}* /etc/nginx/ssl/
openssl rsa -in nginx.key -out nginx.key
openssl rsa -in nginx2.key -out nginx2.key
openssl rsa -in nginx3.key -out nginx3.key
echo website1 > /app/website1/index.html
echo website1 > /app/website2/index.html
echo website1 > /app/website3/index.html
實戰三:實現身份驗證
1、生成密碼賬戶文件
htpasswd -c -m .htpasswd http1
2、在配置文件中修改
vim /etc/nginx/nginx.conf 在location段中指向賬戶密碼文件
location /images { auth_basic "images site"; "提示字" auth_basic_user_file /etc/nginx/conf.d/.htpasswd; }
3、網頁查看驗證 http://172.17.22.22/images/loading.gif