Nginx,apache only allow domain name access to detailed configuration

Source: Internet
Author: User

nginx,apache only allow domain name access to detailed configuration


First, nginx configuration allows only domain access


# setting does not allow IP access to the Web (default_server)

server {

Listen default_server;

server_name _;

return 403;

}

# Set www.meteor-yu.com Domain Access Web

server {

Listen 80;

server_name www.meteor-yu.com;

Location/ngx_status {

Stub_status on;

Access_log off;

}

Location/status {

Include Fastcgi_params;

Fastcgi_pass 127.0.0.1:9000;

Fastcgi_param script_filename $fastcgi _script_name;

}

}


#######

# set to automatically jump to www.meteor-yu.com this domain by accessing the top-level domain meteor-yu.com

server {

Listen 80;

server_name meteor-yu.com;

return 301 Http://www.meteor-yu.com$request_uri;

}



Second, Apache configuration allows only domain access


# Web server built with Apache how to set up a way to disable IP access by using only domain name access

# At present, the use of Apache and Nginx to build a Web server, usually set up after using IP can also access the content of the site,

# How about the Web server built by Apache so that users can only access through the set domain name, not directly through the server's IP address?

# Two methods can be implemented, are modified httpd.conf file to achieve, the following examples.


# # # Method One: In the last side of the httpd.conf file, add the following code


Namevirtualhost *:80

<virtualhost *:80>

ServerName 192.168.116.129 # Web service address

<location/>

Order Allow,deny

Deny from all

</Location>

</VirtualHost>


<virtualhost *:80>

DocumentRoot "/var/www/html"

ServerName www.meteor-yu.com

</VirtualHost>

Description: The red part is the implementation of any access requests that are denied directly through IP, and if you use IP access, you will be prompted to deny access. The blue part is allowed to be accessed through the www.meteor-yu.com domain, and the home directory points to/var/www/html


# # # Method Two: In the last side of the httpd.conf file, add the following code


Namevirtualhost *:80

<virtualhost *:80>

DocumentRoot "/var/www/html/default"

ServerName 192.168.116.129 # Web service address

</VirtualHost>


<virtualhost *:80>

DocumentRoot "/var/www/html"

ServerName www.meteor-yu.com

</VirtualHost>

Note: All the requests through the IP direct access to the/var/www/html/default directory, this can be an empty directory, you can also build a home page file, such as INDEX.HMTL, the first file content can be a declaration, stating that it cannot be accessed directly by IP.


Attention:


1. Direct copy and paste may have Chinese space, please remove these extra spaces.


2. If load balancing is used, limit IP not to write extranet IP, please fill in the intranet IP.


###########

# set to automatically jump to www.meteor-yu.com this domain by accessing the top-level domain meteor-yu.com

# Open Apache Rewirte function

Open httpd.conf and find

# LoadModule Rewrite_module modules/mod_rewrite.so

Get rid of the #

Find allowoverride None change to allowoverride all


# in the last side of the httpd.conf file, add the following code

<virtualhost *:80>

ServerName meteor-yu.com

Redirectmatch ^/(. *) $ http://www.meteor-yu.com/$1

</VirtualHost>



PS: Above this is simply a simple configuration, according to the needs of the appropriate configuration to add


This article is from "Meteor Yu" blog, please be sure to keep this source http://8789878.blog.51cto.com/8779878/1846945

Nginx,apache only allow domain name access to detailed configuration

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.