apache+nginx虛擬主機總配置文件

#server定義一個虛擬主機

server

 

{

listen 80;

#網站的域名,可以有多個

server_namewww.123.com www.abc.com;

#301域名重定向

   if ($host != 'www.123.com')

    {

       rewrite ^/(.*)$ http://www.123.com/$1 permanent;

    }

index index.htmlindex.htm index.php;

#網站根目錄

root /data/www;

#訪問日誌存放路徑,aming爲日誌的格式,自己定義,在nginx配置文件

access_log/tmp/access.log aming;

#訪問控制,對於外部控制,越精確越優先匹配

#deny 127.0.0.1;

#插入一個文件

   #include deny.sh;

         #用戶認證管理後臺

location ~.*admin\.php$ {

         #訪問控制

       #allow 127.0.0.1;

       #deny all;

                   #用戶認證是通過apachehtpasswd工具

       #auth_basic "tingshi";

       #auth_basic_user_file /usr/local/nginx/conf/.htpasswd;

                   #nginxphp-fpm通信的方式,解析php腳本

       include fastcgi_params;

       fastcgi_pass unix:/tmp/php-fcgi.sock;

       fastcgi_index index.php;

                   #解析php的根目錄

       fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

}

 

   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|rar|zip|bz2)$

       {

                                     #gif|jpg|png等靜態文件過期時間

                expires      30d;

                                     #不記錄gif|jpg|png等格式訪問日誌

                access_log off;

 

                                     #圖片,音樂等防盜鏈

                valid_referers none blocked*.123.com *.abc.com;

                if ($invalid_referer)

                {

                    return 403;

                }

       }

 

   location ~ .*\.(js|css)

       {

                                     #js|css靜態文件過期時間

                expires      12h;

                                     #不記錄js|css等格式訪問日誌

                access_log off;

       }

 

location ~\.php$ {

         #nginxphp-fpm通信的方式,解析php腳本

       include fastcgi_params;

       fastcgi_pass unix:/tmp/php-fcgi.sock;

       #fastcgi_pass 127.0.0.1:9000;

       fastcgi_index index.php;

                   #解析php的根目錄

       fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

}

#禁止指定的user_agent(搜索引擎)

   #if ($http_user_agent  ~*'curl|baidu|youdao')

   #    {

   #        return 403;

   #    }

}

 

 

#簡單虛擬主機

server

 

{

   listen 80;

   server_name www.woo.com;

   index index.html index.htm index.php;

   root /data/wordpress;

 

   location ~ \.php$ {

       include fastcgi_params;

       fastcgi_pass unix:/tmp/php-fcgi.sock;

       fastcgi_index index.php;

       fastcgi_param SCRIPT_FILENAME /data/wordpress$fastcgi_script_name;

    }

}

 

 

 

#nginx擴展

Nginx禁止某個目錄解析php

location ~ .*abc/.*\.php?$

       {

        deny all;

       }

 

 

Nginx禁止訪問.txt文件

location ~* \.(txt|doc)$ {

               if (-f $request_filename) {

                  root/home/domain/public_html/test;

                  break;

                  }

               }-

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章