Nginx添加多個(gè)網(wǎng)站,禁止通過ip訪問,禁止訪問某些目錄

同一個(gè)nginx上安裝多個(gè)網(wǎng)站的方法

在nginx.conf的http{}中按照說明修改server{}字段

server {
        listen       80;
        server_name  www.example.com;  #所綁定的域名
        location / {
            root   example;  #該域名對應(yīng)的網(wǎng)站根目錄
            index  index.html index.htm index.php;
        }
        location ~ \.php$ {  #支持php
            root           C:/nginx/html;  #php訪問目錄
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

如果想添加多個(gè)網(wǎng)站,添加多個(gè)server{}并綁定不同的域名,設(shè)置不同的根目錄即可。

以下是禁止通過ip訪問的代碼

server {
        listen 80 default_server;
        server_name _;
        return 444;  #當(dāng)有用戶通過ip訪問時(shí)返回的HTTP狀態(tài)碼
}

禁止訪問某些目錄

location ^~ /admin/test/ {
deny all;
}

這樣就可以禁止訪問/admin/test目錄下的任何文件
原文地址:http://www.mmuaa.com/post/35f1dd5fa5f389cb.html

轉(zhuǎn)載請注明出處 AE博客|墨淵 ? Nginx添加多個(gè)網(wǎng)站,禁止通過ip訪問,禁止訪問某些目錄

發(fā)表評論

路人甲

網(wǎng)友評論(0)