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 thought on “nginx – 优化冗余路径配置。

发表评论

电子邮件地址不会被公开。 必填项已用*标注