1-08 799 views
Nginx+PHP+Mysql+SSL
Ubuntu 14.04 LTS
安装
sudo apt-get install nginx
sudo apt-get install mysql-server
sudo apt-get install php5-fpm php5-mysql
配置PHP
vim /etc/php5/fpm/pool.d/www.conf
修改
#listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9527
重启
/etc/init.d/php5-fpm restart
配置
vim /etc/nginx/conf.d/site.conf
php站点配置
server {
listen 80;
server_name todo.mustodo.com;
access_log /var/log/nginx/todo.mustodo.com.log;
root /var/www/todo.mustodo.com;
index index.php index.html index.htm;
return 301 https://$server_name$request_uri;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9527;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
php站点 SSL 配置
server {
listen 443;
server_name todo.mustodo.com;
access_log /var/log/nginx/todo.mustodo.com.log;
root /var/www/todo.mustodo.com;
index index.php index.html index.htm;
ssl on;
ssl_certificate ssl/1_todo.mustodo.com_bundle.crt;
ssl_certificate_key ssl/2_todo.mustodo.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9527;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
wordpress配置
server {
listen 80;
server_name blog.nuxui.com;
access_log /var/log/nginx/blog.nuxui.com.log;
root /var/www/blog.nuxui.com;
index index.php index.html index.htm;
return 301 https://$server_name$request_uri;
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
fastcgi_pass 127.0.0.1:9527;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
wordpress SSL 配置
server {
listen 443;
server_name blog.nuxui.com;
access_log /var/log/nginx/blog.nuxui.com.log;
root /var/www/blog.nuxui.com;
index index.php index.html index.htm;
ssl on;
ssl_certificate ssl/1_blog.nuxui.com_bundle.crt;
ssl_certificate_key ssl/2_blog.nuxui.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
fastcgi_pass 127.0.0.1:9527;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
数据库备份与还原
备份
mysqldump -h 127.0.0.1 -u root -p example > example.sql
还原
mysql -u root -p
CREATE DATABASE IF NOT EXISTS example DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
use example;
mysql>source /path/example.sql;