Set Nginx prohibit IP direct access, only through the specified domain name access

Source: Internet
Author: User

To set the configuration file disableip.conf:

    1. server {
    2.     listen 80;
    3.     server_name _;
    4.     return500;
    5. }

This is the final use of the configuration file, is also found on the Internet, one of the common configuration, initially the Conf file in the Sites-available folder, trying to use a variety of parameters are not working, and eventually try to put disableip.conf files into the CONF.D folder , this is because in the nginx.conf file:

    1. include /etc/nginx/conf.d/*.conf;
    2. include /etc/nginx/sites-enabled/*;

The first reference is the CONF.D path under the configuration file, the disableip.conf file into the Conf.d folder to make this server at the forefront, the rule is first applied, the modification is completed after the restart Nginx ( service nginx restart ), the following test:

    1. Enter the IP address directly
    2. Enter the domain name

The implementation of Nginx prohibit IP direct access to the site, only allowed through the set of domain name access.

Set Nginx prohibit IP direct access, only through the specified domain name access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.