Linux web怎么设置只允许域名访问

如题所述

要实现只用域名访问而不用IP访问,要看所使用的web服务器软件,以nginx为例,可以通过如下方法进行设置:

  1、用vim打开nginx的配置文件,一般为nginx/conf/nginx.conf
  2、在server的设置里面添加如下内容即可:
  #禁止IP访问
  server{
  listen 80 default;
  server_name _;
  return 500;
  }
  或者
  server {
  listen 80 dufault;
  server_name _;
  rewrite ^(.*) http://域名 permanent;
   }追问

重启失败了。。。。。

温馨提示:内容为网友见解,仅供参考
第1个回答  2016-05-25
如果是apache,使用虚拟机配置网站追问

怎么配置?

追答

NameVirtualHost 192.168.1.1

ServerAdmin webmaster@abc.com
DocumentRoot /web/htdocs/
ServerName www.abc.com
ErrorLog logs/abc.com-error_log
CustomLog logs/abc-access_log common

追问

还是可以用IP访问。。。。。。。。。。。

相似回答