方法一:修改 Nginx 配置文件 nginx.conf
Nginx 配置访问 IP 可以修改 nginx.conf 文件,只需要在 server
中添加 allow
和 deny
的 IP 即可,如下:
server {
listen 80;
server_name localhost;
allow all;
deny 123.123.123.123;
error_page 500 502 503 504 /50x.html;
}
注意!上面的配置中 allow
必须在 deny
的前面配置,不然 allow
不生效。
Nginx 中允许或者拒绝某个 IP 访问是这么写的:
allow 192.168.0.1;
deny 192.168.0.2;
如果你需要对整个 IP 段设置不允许访问,可以这么写:
deny 123.0.0.0/8; // 封 123.0.0.1~123.255.255.254 这个段的ip
deny 123.123.0.0/16; // 封 123.123.0.1~123.123.255.254 这个段的ip
deny 123.123.123.0/24; // 封 123.123.123.1~123.123.123.254 这个段的ip
deny all; // 封所有ip
说明,allow
跟 deny
配置相同,如果需要开放某个 IP 段,只需要把上面的 deny
改成 allow
。
另外需要注意,该配置修改需要重启 Nginx 服务器才能生效。
方法二:修改网站配置文件 .htaccess
除了修改 Nginx 配置文件之外,还可以通过修改网站配置文件 .htaccess 来限制某 IP(段)访问,方法如下。
将以下内容保存为 .htaccess 文件,上传至网站根目录。如果原来已经存在 .htaccess 文件的,将以下内容加到该文件开头。
Order allow,deny
allow from all
deny from 123.123.123.123
如果要限制一个 IP 段,比如要限制 123.123.123.* 这个 C 段,则输入:
Order allow,deny
allow from all
deny from 123.123.123
以上内容表示拒绝 123.123.123 开头的所有 IP,其他 IP 允许。
如果要限制多个 IP 段,中间用空格隔开,如:
Order allow,deny
allow from all
deny from 111.111.111 111.222.222 111.333.333
说明,该配置不用重启 web 服务器,修改立即生效。
此外,该方法适用任何 web 网站,例如 IIS、Apache 网站。
This was both informative and hilarious! For further reading, check out: LEARN MORE. What do others think?
You really make it appear really easy together with your
presentation but I to find this topic to be really one thing which I
feel I would never understand. It kind of feels too complex and very broad for me.
I am looking forward to your next submit, I’ll try to get the cling of it!
Escape room lista
I like this blog very much, Its a rattling nice billet to read and find info.?
I like this website it’s a master piece! Glad I found this on google.
Euro travel guide
Very nice post. I definitely appreciate this site. Thanks!
An interesting discussion is definitely worth comment. I do believe that you should write more on this subject matter, it might not be a taboo matter but generally people do not talk about these subjects. To the next! Best wishes.
Your style is unique in comparison to other folks I’ve read stuff from. Thanks for posting when you have the opportunity, Guess I’ll just bookmark this blog.
Hi there! I simply wish to give you a big thumbs up for your great information you’ve got right here on this post. I am returning to your website for more soon.
This excellent website really has all the information I needed concerning this subject and didn’t know who to ask.
Oh my goodness! Impressive article dude! Thank you, However I am having issues with your RSS. I don’t understand why I am unable to join it. Is there anybody getting similar RSS issues? Anybody who knows the answer can you kindly respond? Thanx.
Great site you’ve got here.. It’s difficult to find excellent writing like yours these days. I seriously appreciate people like you! Take care!!
This site was… how do you say it? Relevant!! Finally I have found something which helped me. Cheers.
Great web site you have here.. It’s hard to find quality writing like yours these days. I truly appreciate individuals like you! Take care!!
An outstanding share! I’ve just forwarded this onto a coworker who has been doing a little research on this. And he in fact ordered me lunch due to the fact that I discovered it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanx for spending some time to discuss this topic here on your blog.
Saved as a favorite, I love your web site!
May I just say what a comfort to find someone that really understands what they are talking about over the internet. You actually realize how to bring a problem to light and make it important. More people have to check this out and understand this side of the story. It’s surprising you are not more popular since you surely have the gift.
I absolutely love your blog.. Very nice colors & theme. Did you develop this amazing site yourself? Please reply back as I’m looking to create my very own blog and would love to learn where you got this from or just what the theme is named. Thank you!
Way cool! Some very valid points! I appreciate you writing this article plus the rest of the website is extremely good.
Oh my goodness! Amazing article dude! Thanks, However I am going through problems with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anyone else having similar RSS issues? Anyone that knows the answer will you kindly respond? Thanks!
This is the perfect web site for anybody who would like to understand this topic. You realize a whole lot its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a new spin on a topic which has been written about for decades. Excellent stuff, just wonderful.
You’re so awesome! I don’t believe I’ve truly read through anything like that before. So nice to discover somebody with some genuine thoughts on this issue. Really.. thank you for starting this up. This site is one thing that is required on the web, someone with a little originality.
Hello there! I could have sworn I’ve been to this blog before but after going through many of the posts I realized it’s new to me. Anyhow, I’m certainly pleased I found it and I’ll be bookmarking it and checking back frequently!
You need to be a part of a contest for one of the highest quality blogs on the internet. I most certainly will recommend this website!
I was extremely pleased to find this site. I need to to thank you for your time just for this fantastic read!! I definitely really liked every little bit of it and I have you book marked to see new stuff in your site.
You ought to be a part of a contest for one of the best blogs online. I’m going to recommend this site!
I really love your website.. Great colors & theme. Did you develop this website yourself? Please reply back as I’m planning to create my very own site and would like to know where you got this from or what the theme is called. Kudos.
Hi there! This post couldn’t be written much better! Going through this article reminds me of my previous roommate! He constantly kept talking about this. I will send this post to him. Fairly certain he’ll have a good read. I appreciate you for sharing!
Greetings! Very useful advice within this article! It is the little changes that will make the most important changes. Many thanks for sharing!
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/ru/register?ref=V3MG69RO
Everything is very open with a really clear explanation of the challenges. It was truly informative. Your website is very helpful. Thank you for sharing.
I truly love your site.. Very nice colors & theme. Did you make this amazing site yourself? Please reply back as I’m attempting to create my own site and would love to know where you got this from or exactly what the theme is called. Appreciate it.
After going over a handful of the blog articles on your site, I seriously like your technique of blogging. I book marked it to my bookmark webpage list and will be checking back soon. Please check out my web site too and let me know how you feel.
After I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and now every time a comment is added I receive four emails with the exact same comment. There has to be a way you are able to remove me from that service? Many thanks.
I must thank you for the efforts you have put in penning this blog. I’m hoping to see the same high-grade blog posts by you in the future as well. In truth, your creative writing abilities has inspired me to get my very own site now 😉
Very good blog post. I definitely appreciate this site. Continue the good work!
This blog was… how do you say it? Relevant!! Finally I have found something that helped me. Kudos!
I’m impressed, I must say. Rarely do I come across a blog that’s both educative and entertaining, and without a doubt, you’ve hit the nail on the head. The problem is something which not enough folks are speaking intelligently about. I am very happy that I came across this during my hunt for something relating to this.
Way cool! Some extremely valid points! I appreciate you penning this write-up and also the rest of the website is also very good.
Hi! I just wish to offer you a big thumbs up for your excellent information you have here on this post. I will be returning to your blog for more soon.
I could not resist commenting. Perfectly written!
This is a topic that’s near to my heart… Many thanks! Exactly where are your contact details though?
Having read this I believed it was very enlightening. I appreciate you finding the time and effort to put this content together. I once again find myself personally spending a lot of time both reading and posting comments. But so what, it was still worth it!
Hi there! This blog post couldn’t be written much better! Looking through this post reminds me of my previous roommate! He continually kept talking about this. I will send this information to him. Fairly certain he’ll have a good read. I appreciate you for sharing!
I’m more than happy to uncover this website. I want to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you book marked to see new stuff on your site.
When I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I recieve four emails with the same comment. Perhaps there is a means you are able to remove me from that service? Thank you.
Good day! I could have sworn I’ve visited this website before but after browsing through a few of the articles I realized it’s new to me. Nonetheless, I’m certainly pleased I came across it and I’ll be book-marking it and checking back frequently.
Way cool! Some extremely valid points! I appreciate you writing this article and also the rest of the website is very good.
Right here is the perfect website for anybody who hopes to find out about this topic. You know a whole lot its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a new spin on a topic that has been written about for decades. Excellent stuff, just wonderful.
Right here is the perfect blog for anybody who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I really will need to…HaHa). You definitely put a brand new spin on a topic which has been discussed for decades. Great stuff, just great.
I have actually struggled with blood sugar variations for several years,
and it truly influenced my power levels throughout
the day. Considering that beginning Sugar Protector,
I feel more well balanced and alert, and I
do not experience those afternoon plunges any longer!
I like that it’s a natural service that works with no rough side effects.
It’s truly been a game-changer for me
After going over a handful of the blog posts on your website, I truly like your way of writing a blog. I added it to my bookmark webpage list and will be checking back in the near future. Please check out my website too and tell me what you think.