Nginx virtual host configuration tutorial, nginx virtual host tutorial

Source: Internet
Author: User
Tags sendfile

Nginx virtual host configuration tutorial, nginx virtual host tutorial

It is to start multiple websites on one server.

There are two ways to differentiate different websites:

1. Different domain names

2. Different ports

Differentiate virtual machines through ports

Nginx configuration file:

/usr/local/nginx/conf/nginx.conf
# User nobody; worker_processes 1; # error_log logs/error. log; # error_log logs/error. log notice; # error_log logs/error. log info; # pid logs/nginx. pid; events {worker_connections 1024;} http {include mime. types; default_type application/octet-stream; # log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request"' # '$ status $ response "$ http_referer"' # '"$ http_user_agent" "$ http_x_forwarded_for "'; # access_log logs/access. log main; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; # gzip on; # A server node is a virtual host server {# port listen 80; server_name localhost; # charset koi8-r; # access_log logs/host. access. log main; location/{# Html is the root html directory under the nginx installation directory; index index.html index.htm ;}}}

You can configure multiple servers and multiple virtual hosts.

Add a VM:

# User nobody; worker_processes 1; # error_log logs/error. log; # error_log logs/error. log notice; # error_log logs/error. log info; # pid logs/nginx. pid; events {worker_connections 1024;} http {include mime. types; default_type application/octet-stream; # log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request"' # '$ status $ response "$ http_referer"' # '"$ http_user_agent" "$ http_x_forwarded_for "'; # access_log logs/access. log main; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; # gzip on; server {listen 80; server_name localhost; # charset koi8-r; # access_log logs/host. access. log main; location/{root html; index index.html index.htm ;}# copy a server, modify the relevant information on the server {listen 81; server_name localhost; # charset koi8-r; # access_log logs/host. access. log main; location/{root html81; index index.html index.htm ;}}}

Reload the configuration file

[Root @ localhost nginx] # sbin/nginx-s reload

Copy html directory

[Root @ nginx] # cp-r html html81

Modify related content

[Root @ nginx] # vi html81/index.html

Reload the configuration file

[Root @ localhost nginx] # sbin/nginx-s reload

Access through a browser:

Successful!

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.