ubuntu VPS nginx(1.4.6) 禁止其他域名访问你的服务器

ubuntu VPS nginx(1.4.6) 禁止其他域名访问你的服务器

ubuntu下的nginx配置文件在、etc/nginx/sites-ava/default

修改其配置即可。
如果要禁止IP访问  只需要添加服你器名称即可。

下面代码删除了注释#部分
server {

        listen 80;
        [b]server_name www.test.com www.test2.com; [/b]
        listen [::]:80 default_server ipv6only=on;
        root /usr/share/nginx/html/3dvr;
        index index.php index.html index.htm;
        location / {

                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
}






如果需要绑定更多域名,可以添加域名列表,放在配置文件夹下,但是文件要以.conf后缀名。即上层目录的nginx.conf下,然后在default文件中include进来就可以了
像这样
include /etc/nginx/conf.d/*.conf;



================================================================




三、不带www的域名加301跳转
若不带 www 的域名需加 301 跳转,则先绑定不带 www 的域名,且无需写网站目录,直接进行 301 跳转,如:
server
{
listen 80;
server_name server110.com;
rewrite ^/(.*) http://www.server110.com/$1 permanent;
}


四、添加404网页
添加 404 网页,可以直接在配置中添加,如:
server  
{  
listen             80;  
server_name  www.server110.com;                          #绑定域名  
index index.htm index.html index.php;   #默认文件  
root /home/www/server110.com;                     #网站根目录
include location.conf;                         #调用其他规则,也可去除
error_page 404   /404.html;  
}
  



下面的来源
https://help.aliyun.com/knowledge_detail/41467.html







猜你喜欢

转载自gaoziqiang.iteye.com/blog/2316901
vps
今日推荐