##关键文件

etc/nginx/conf.d/ 目录存放各站点的配置 etc/nginx/nginx.conf nginx的配置

为了方便查找,在conf.d目录中的文件使用域名倒过来写的方式,比如*“com.ibm.www”*这样。

##站点配置文件实例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
server {
listen 80;
server_name www.xxx.com; 
root /home/www/;
index index.html index.htm index.php;

        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }
 
        location ~ .*\.php(\/.*)*$ {
            include fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

##301重定向实例

1
2
3
4
5
server {
listen 80;
server_name xxx.com; 
rewrite ^/(.*) http://www.xxx.com/$1 permanent;
}
  • redirect – 返回临时重定向的HTTP状态302
  • permanent – 返回永久重定向的HTTP状态301