apache+nginx虛擬機器主機總設定檔

來源:互聯網
上載者:User

標籤:詳解

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

                   #使用者認證是通過apache的htpasswd工具

       #auth_basic "tingshi";

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

                   #nginx和php-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$ {

         #nginx和php-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;

                  }

               }-

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


本文出自 “11736718” 部落格,請務必保留此出處http://11746718.blog.51cto.com/11736718/1876252

apache+nginx虛擬機器主機總設定檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.