nginx 服务器块
一旦设置并配置了 php5-fpm 和 wordpress 设置,就可以配置/etc/nginx/conf/nginx.conf 文件,如下所示。
你需要在服务器块内定义位置块,并按照定义重写 URL。
server {
listen 443 ssl;
server_name abc.co.uk;
root /home/ubuntu/www/abc/current/public;
try_files $uri/index.html $uri @unicorn;
ssl on;
ssl_certificate /etc/nginx/ssl/abc.crt;
ssl_certificate_key /etc/nginx/ssl/abc.key;
location /blog/wp-admin/ {
root /var/www/html/;
index index.php;
try_files $uri $uri/ /index.php?$args;
location ~* \.(js|css|xml|txt|jpg)$ {
expires 14d;
root /var/www/html/;
access_log off;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_index index.php;
include /etc/nginx/conf/fastcgi_params;
}
}
location ^~ /blog {
root /var/www/html/;
index index.php;
try_files $uri $uri/ /index.php?$args;
rewrite ^/blog/(.*)+$ /blog/index.php?$1;
location ~* \.(js|css|xml|txt|jpg)$ {
expires 14d;
root /var/www/html/;
access_log off;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_index index.php;
include /etc/nginx/conf/fastcgi_params;
}
}
}