Nginx a virtual host based on domain name \ port

Source: Internet
Author: User

To implement three types of virtual hosts need to modify the code under Http\server in the Nginx nginx.conf file, share two ways to configure a virtual host:

# domain-based virtual host
server {
        listen;  # Listen to the Port
        server_name a.com, listen to the domain name, note that localhost is also a domain name, can be modified in/etc/hosts

        location/{
                root/var/www/a.com;   # root directory positioning
                index index.html;  # Default access page positioning
        }
    }
# Port-based virtual host configuration
    server {
        listen 8080;  # Listening Port
        server_name 192.168.1.204;  # monitor IP or domain name

        location/{
                root/var/www/html8080;  # root directory positioning
                index index.html;  # Default access page positioning
        }
    }

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.