Nginx个别配置实例:
环境背景:CentOS 7.2 本机IP 10.1.0.26
一、Nginx+Fastcgi
一、yum安装nginx,php-fpm,mariadb-server,php-mysql,php-gd php-mbstring php-mcrypt
#因为我之前都装好了,所以显示已安装 [[email protected] 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
二、更改/etc/php-fpm.d/www.conf
更改几项配置 user和group改为nginx user = nginx ; RPM: Keep a group allowed to write in log dir. group = nginx 打开ping、pang和status |
三、创建/var/lib/php/session,并且更改属组属主
[[email protected] conf.d]# mkidr /var/lib/php/session [[email protected] conf.d]# chown -R nginx:nginx /var/lib/php/session
四、更改/etc/nginx/conf.d/default.conf
五、启动mariadb,php-fpm,以及nginx服务,然后测试!
二、Nginx+Cache+FastCGI
一、创建缓存文件并更改属主属组
[[email protected] conf.d]# mkdir /var/cache/nginx/fastcgi_cache
二、配置nginx主配置文件
三、编辑/etc/nginx/conf.d/default.conf
四、重新启动Nginx服务并通过外界访问测试
注意:由于上面的cache在location 以.php结尾配置断中,所以并不会缓存ping和status的状态结果
三、Nginx+SSL
注意:/etc/nginx/conf.d/default.conf重置为最原始的状态。
一、创建Nginx的SSL配置文件
二、配置ssl证书即私钥文件
[[email protected] ~]# cd /etc/pki/CA/
[[email protected] CA]# touch index.txt [[email protected] CA]# echo 01 > serial [[email protected] CA]# cd /etc/nginx/ [[email protected] nginx]# mkdir ssl [[email protected] nginx]# cd ssl [[email protected] ssl]# (umask 077;openssl genrsa -out nginx.key 2048) Generating RSA private key, 2048 bit long modulus ..+++ ..........................................................+++ e is 65537 (0x10001) [[email protected] ssl]#
#自己给自己颁发证书 [[email protected] ssl]# openssl ca -in nginx.csr -out nginx.crt
三、重启服务并使用浏览器测试
注意:因为443和80端口为两个不同的端口,http://10.1.0.26和https://101.0.26的结果是不一样的,如果想让客户端输入http://10.1.0.26直接转到https,可以使用rewrite语句
谢谢浏览...
转载于:https://blog.51cto.com/dashui/1867075