Configuring an Nginx standalone virtual host file

Source: Internet
Author: User

The master configuration file is nignx.conf, all the configuration files contained in the master profile are placed uniformly into Extra directory, the configuration file for the virtual host is named nginx_vhosts.conf, You can also configure each virtual host as a separate configuration file.

[Email protected]]# pwd

/application/nginx/conf

[Email protected]]# mkdir Extra

[email protected]]# vi nginx.conf # contents are as follows

User Nginx Nginx;

Worker_processes 8;

Error_log/app/logs/nginx_error.log Crit;

PID Logs/nginx.pid;

Events {

Use Epoll;

Worker_connections 1024;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Log_format Main ' $remote _addr-$remote _user[$time _local] "$request" '

' $status $body _bytes_sent ' $http _referer '

' "$http _user_agent" "$http _x_forwarded_for";

Sendfile on;

Keepalive_timeout 65;

include extra/nginx_vhosts.conf; # referencing a standalone virtual file

}

[email protected]]# cat nginx_vhosts.conf  # The contents are as follows

server {

Listen 80;

server_name www.51cto.com 51cto.com; #域名

Location/ {

root/data0/www/www; #站点目录

Index index.html index.htm;

Access_log/app/logs/www_access.log main; #日志文件

}

}

###

server {

Listen 80;

server_name bbs.51cto.com;

Location/{

Root/data0/www/bbs;

Index index.html index.htm;

Access_log/app/logs/bbs_access.log main;

}

}

###

server {

Listen 80;

server_name blog.etiantian.org;

Location/{

Root/data0/www/blog;

Index index.html index.htm;

Access_log/app/logs/blog_access.log main;

}

}

#以上是把3个虚拟站点目录配置, separated from the nignx.conf, set up a nginx_vhosts.conf under the extra.

#也可以从nginx_vhosts. conf There are 3 separate virtual host files in the virtual host file:

[Email protected]]# sed-n ' 10,19p ' nginx_vhosts.conf > bbs.conf

[Email protected]]# sed-n ' 20,30p ' nginx_vhosts.conf > blog.conf

[Email protected]]# sed-n ' 1,9p ' nginx_vhosts.conf > www.conf

After dividing the virtual master file into three separate files, we will do three introductions in nginx.conf, as follows:

include extra/nginx_vhosts.conf; # referencing a standalone virtual file

Include extra/bbs.conf;

Include extra/blog.conf;

include extra/ www.conf;

in Summary, there are three types of virtual host configuration: One is so that the virtual host configuration is placed in the nginx.conf configuration, the second way, the establishment of the extra directory, in this directory to establish a nginx_ vhosts.conf, three virtual Site Directory profiles are placed in the file, and the third is to establish three-person independent virtual host files, which are introduced through the master configuration file.


This article is from the "sky9890" blog, make sure to keep this source http://sky9896.blog.51cto.com/2330653/1793452

Configuring an Nginx standalone virtual host file

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.