環境背景:CentOS 7.2 本機IP 10.1.0.26
php
1、Nginx+Fastcgimysql
1、yum安裝nginx,php-fpm,mariadb-server,php-mysql,php-gd php-mbstring php-mcryptnginx
#由於我以前都裝好了,因此顯示已安裝 [root@localhost conf.d]# yum install nginx php-fpm mariadb-server php-mysql php-gd php- mbstring php-mcrypt Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00:00 epel | 4.3 kB 00:00:00 Determining fastest mirrors Package matching 1:nginx-1.6.3-6.el7.x86_64 already installed. Checking for update. Package php-fpm-5.4.16-36.el7_1.x86_64 already installed and latest version Package 1:mariadb-server-5.5.44-2.el7.centos.x86_64 already installed and latest version Package php-mysql-5.4.16-36.el7_1.x86_64 already installed and latest version Package php-gd-5.4.16-36.el7_1.x86_64 already installed and latest version Package php-mbstring-5.4.16-36.el7_1.x86_64 already installed and latest version Package php-mcrypt-5.4.16-3.el7.x86_64 already installed and latest version Nothing to do
2、更改/etc/php-fpm.d/www.confsql
更改幾項配置centos user和group改成nginx瀏覽器 user = nginx緩存 ; RPM: Keep a group allowed to write in log dir.bash group = nginxsession 打開ping、pang和statuside |
3、建立/var/lib/php/session,而且更改屬組屬主
[root@localhost conf.d]# mkidr /var/lib/php/session [root@localhost conf.d]# chown -R nginx:nginx /var/lib/php/session
4、更改/etc/nginx/conf.d/default.conf
5、啓動mariadb,php-fpm,以及nginx服務,而後測試!
2、Nginx+Cache+FastCGI
1、建立緩存文件並更改屬主屬組
[root@localhost conf.d]# mkdir /var/cache/nginx/fastcgi_cache
2、配置nginx主配置文件
3、編輯/etc/nginx/conf.d/default.conf
4、從新啓動Nginx服務並經過外界訪問測試
注意:因爲上面的cache在location 以.php結尾配置斷中,因此並不會緩存ping和status的狀態結果
3、Nginx+SSL
注意:/etc/nginx/conf.d/default.conf重置爲最原始的狀態。
1、建立Nginx的SSL配置文件
2、配置ssl證書即私鑰文件
[root@localhost ~]# cd /etc/pki/CA/
[root@localhost CA]# touch index.txt [root@localhost CA]# echo 01 > serial [root@localhost CA]# cd /etc/nginx/ [root@localhost nginx]# mkdir ssl [root@localhost nginx]# cd ssl [root@localhost ssl]# (umask 077;openssl genrsa -out nginx.key 2048) Generating RSA private key, 2048 bit long modulus ..+++ ..........................................................+++ e is 65537 (0x10001) [root@localhost ssl]#
#本身給本身頒發證書 [root@localhost ssl]# openssl ca -in nginx.csr -out nginx.crt
3、重啓服務並使用瀏覽器測試
注意:由於443和80端口爲兩個不一樣的端口,http://10.1.0.26和https://101.0.26的結果是不同的,若是想讓客戶端輸入http://10.1.0.26直接轉到https,能夠使用rewrite語句
謝謝瀏覽...