ubuntu VPS nginx (1.4.6) prohibits other domain names from accessing your server

ubuntu VPS nginx (1.4.6) Forbid other domain names to access

the nginx configuration file under your server ubuntu,

modify its configuration in etc/nginx/sites-ava/default.
If you want to prohibit IP access, you only need to add your server name.

The following code removes the comment # part
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;
}






If you need to bind more domain names, you can add a list of domain names and put them in the configuration folder, but the file should be suffixed with .conf. That is, under nginx.conf in the upper directory, and then include it in the default file,
like this
include /etc/nginx/conf.d/*.conf;



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




3. Add 301 redirect to the domain name without www If the domain name
without www needs to add 301 redirect, then bind the domain name without www first, and do not need to write Website directory, direct 301 jump, such as:
server
{
listen 80;
server_name server110.com;
rewrite ^/(.*) http://www.server110.com/$1 permanent;
}


4. Add 404 webpage
Add 404 webpage, you can add it directly in the configuration, such as:
server  
{  
listen             80;  
server_name www.server110.com; #Bind domain name  
index index.htm index.html index.php; #default file  
root /home/www/server110.com; #Website root directory
include location.conf; #Call other rules, can also be removed
error_page 404   /404.html;  
}
  



Source below
https://help.aliyun.com/knowledge_detail/41467.html







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326513038&siteId=291194637