首页 > nginx > nginx server_name 设置

nginx server_name 设置

2010年6月1日 eric 发表评论 阅读评论

在看博客访问明细的时候发现有人直接用IP 访问我的博客,看上去很不爽,有点好像站点被别人拿下的感觉,然后就在nginx官方网站看了一下,可以禁止直接IP访问,所以我就记录下。官方原文:

If you do not want to process requests with undefined “Host” header lines, you may define a default server that just drops the requests:

server {
listen 80 default_server;
server_name _;
return 444;
}

我加的配置:

server {
listen 80 default_server;
server_name _;
rewrite ^ http://www.nginxs.com$request_uri?;
}

直接返回错误不好吧,毕竟还是想让别人来访问送IP的,呵呵!!!

随后还看到 server_name 支持 正则表达式,如果这样的话,就很容易让二级域名对应相应的目录了,做了一下测试,效果不错。

server {
listen 80;
server_name ~^(.+)\.nginxs\.com$;

location / {
root /var/www/$1;
index index.html index.htm index.php;
}
}

PS:下面这段是写给新手的,高手见谅。
这样就可以了,在 /var/www/ 目录下 新建一个 123 文件夹,然后在里面新建一个 index.html 内容为 123 ,然后 访问 123.nginxs.com 就可以 访问到内容为 123的页面。

然后重启 nginx
/etc/init.d/nginx restart

转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/176.html

分类: nginx 标签: ,
  1. 2017年9月27日12:41 | #1

    Pretty nice post. I just stumbled upon your
    weblog and wished to say that I’ve really enjoyed browsing
    your blog posts. In any case I will be subscribing to
    your feed and I hope you write again very soon!

  2. 2017年9月27日18:19 | #2

    WOW just what I was searching for. Came here by searching for backpacking travel

  3. 2017年9月27日21:29 | #3

    Hi there mates, how is everything, and what you wish for to say on the topic of this piece of writing, in my view its genuinely amazing designed for me.

  4. 2017年9月27日21:54 | #4

    Great article! We are linking to this particularly great content
    on our site. Keep up the great writing.

  5. 2017年9月27日23:35 | #5

    Definitely consider that which you stated. Your favorite reason appeared to
    be at the web the easiest factor to keep in mind of. I say to you, I certainly
    get irked while folks think about issues that they just don’t understand about.
    You controlled to hit the nail upon the highest and also defined out the whole thing without having side-effects ,
    people could take a signal. Will likely be again to get more.
    Thanks

  6. 2017年9月28日07:42 | #6

    Hey there! I’m at work browsing your blog from my new iphone 4!

    Just wanted to say I love reading through your blog and look
    forward to all your posts! Keep up the excellent work!

  7. 2017年9月28日21:46 | #7

    Howdy! Would you mind if I share your blog with my
    facebook group? There’s a lot of people that I think would really appreciate your
    content. Please let me know. Thank you

  8. 2017年9月29日14:13 | #8

    I’m very pleased to uncover this web site. I want to to thank you for ones time
    for this fantastic read!! I definitely really liked every bit of it and i also have you book marked to look at new stuff in your site.

  9. 2017年9月30日04:23 | #9

    Hello mates, its wonderful paragraph about educationand completely explained,
    keep it up all the time.

  10. 2017年10月1日12:54 | #10

    I was wondering if you ever thought of changing the layout of your website?
    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so
    people could connect with it better. Youve got an awful lot of text for only
    having one or two images. Maybe you could
    space it out better?

  11. 2017年10月2日08:08 | #11

    Fabulous, what a weblog it is! This webpage gives useful facts to
    us, keep it up.

  12. 2017年10月4日14:58 | #12

    I go to see everyday some web pages and information sites to read articles or reviews, but
    this blog provides quality based articles.

  13. 2017年10月5日15:15 | #13

    A motivating discussion is worth comment. I do believe
    that you should publish more on this topic, it might
    not be a taboo matter but usually people
    don’t discuss such issues. To the next! Many thanks!!

  14. 2017年10月5日15:52 | #14

    I’m gone to convey my little brother, that he should also go to see this weblog on regular basis to obtain updated from most recent information.

  15. 2017年10月6日06:26 | #15

    viagra pills for sale
    generic viagra
    viagra buy spain

  16. 2017年10月6日12:44 | #16

    I believe this is one of the so much important info for me.

    And i am satisfied reading your article. However wanna observation on few basic things, The web site style is perfect, the articles is in point of fact great : D.

    Excellent job, cheers

  17. 2017年10月8日21:44 | #17

    Does your site have a contact page? I’m having trouble locating it but, I’d like
    to send you an email. I’ve got some suggestions for your
    blog you might be interested in hearing. Either way, great
    website and I look forward to seeing it develop over
    time.

  18. 2017年10月9日13:19 | #18

    Hello, i believe that i noticed you visited my website so i came to
    return the want?.I’m trying to to find issues to enhance my web site!I suppose its adequate to make use of a few of your ideas!!

  19. 2017年10月12日03:01 | #19

    This design is spectacular! You certainly know
    how to keep a reader entertained. Between your wit and your videos,
    I was almost moved to start my own blog (well,
    almost…HaHa!) Excellent job. I really enjoyed what you had to say,
    and more than that, how you presented it.
    Too cool!

  20. 2017年10月13日17:52 | #20

    Its such as you read my mind! You seem to understand so much about this, such as you wrote
    the book in it or something. I feel that you simply can do
    with a few % to force the message house a little bit, but instead
    of that, that is excellent blog. An excellent read.
    I’ll definitely be back.

  21. 2017年10月13日21:54 | #21

    Hello there, just became alert to your blog through Google, and found that it is really informative.
    I am gonna watch out for brussels. I’ll appreciate if you continue this in future.
    A lot of people will be benefited from your writing.
    Cheers!

  22. 2017年10月15日03:05 | #22

    What a material of un-ambiguity and preserveness of precious experience concerning unpredicted feelings.

  23. 2017年10月16日10:49 | #23

    Good day! This is kind of off topic but I need some guidance from an established blog.
    Is it very hard to set up your own blog? I’m not very techincal
    but I can figure things out pretty quick. I’m
    thinking about setting up my own but I’m not sure where
    to start. Do you have any points or suggestions?

    Thanks

  24. 2017年10月17日23:36 | #24

    Nice post. I learn something new and challenging on blogs I stumbleupon every day.
    It will always be helpful to read through articles from other writers and
    use a little something from other websites.

  25. 2017年10月18日00:43 | #25

    Awesome! Its in fact amazing article, I have got much clear idea about from this article.

  26. 2017年10月20日09:48 | #26

    I’m not sure where you’re getting your info, but great topic.
    I needs to spend some time learning much more or understanding more.
    Thanks for magnificent info I was looking for
    this info for my mission.

  27. 2017年10月20日19:33 | #27

    I enjoy what you guys tend to be up too. Such clever work
    and exposure! Keep up the awesome works guys I’ve added
    you guys to my personal blogroll.

评论分页
1 2 3 176
订阅评论
2+5= (必填)