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;
    }

  }

}