咱来写个CentOS系列的搭建教程(强制使用SSL):
首先安装EPEL源或者Nginx官方的源:
yum install epel-release
安装nginx:
yum install nginx
然后安装php和相关的扩展:
yum install php php-fpm php-xml curl
编辑 /etc/php.ini:
cgi.fix_pathinfo = 0
date.timezone = Asia/Shanghai
expose_php = Off
编辑 /etc/php-fpm.d/www.conf:
listen = /var/run/php-fpm/php-fpm.sock
修改 Unix user/group of processes 下的 apache 为 nginx
cd /etc/nginx/conf.d
新建mail.xxx.com.conf:
#
mail.xxx.com# Redirect HTTP to HTTPS for security
server {
listen 80;
listen [::]:80;
server_name
mail.xxx.com;
# redirect http to https #
rewrite ^/(.*)$
https://mail.xxx.com/$1 permanent;
}
# HTTPS
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name
mail.xxx.com;
ssl on;
ssl_certificate /etc/nginx/mail.xxx.com.crt;
ssl_certificate_key /etc/nginx/mail.xxx.com.key;
root /home/wwwroot/
mail.xxx.com;
index index.html index.htm index.php;
error_page 404 /404.html;
# Mail
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Mail Security
location ^~ /data {
deny all;
}
}
最后:
nginx -t 查错
service php-fpm restart
service nginx restart