nginx – 优化冗余路径配置。

server {
        listen       80;
        server_name  phpmyadmin.lezi.com;
        location / {
            root   /var/www/html/phpMyAdmin;
            index  index.php;
        }
            location ~ \.php$ {
                        root  /var/www/html/phpMyAdmin;
                        fastcgi_pass www.sgfblog.com:9000;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME /var/www/html/phpMyAdmin$fastcgi_script_name;
                        fastcgi_param  PATH_INFO $request_uri;
                        include fastcgi_params;
           }
   }

上面配置中可以看出路径非常冗余,如过修改路径需要改三个地方,
其实可以set一个变量,将路径写入变量,这样就下次修改的时候就只需要修改1个变量就好了。如下:

server {
        listen       80;
        server_name  phpmyadmin.lezi.com;
        set $root '/var/www/html/phpMyAdmin';
        location / {
            root   $root;
            index  index.php;
        }
            location ~ \.php$ {
                        root  $root;
                        fastcgi_pass www.sgfblog.com:9000;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
                        fastcgi_param  PATH_INFO $request_uri;
                        include fastcgi_params;
           }
   }
发表评论?

1 条评论。

  1. 又是那么多的代码,好困啊。。。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>