Nginx_include Publishing Multiple Web sites

Source: Internet
Author: User
Tags hosting vps

We have a VPS host later, in order not to waste the powerful resources of the VPS (compared to the shared host more than 1000 sites crowded on a machine), often want to let the VPS do something idea, silver can not white flowers AH:). Placing multiple websites or blogs is a good idea, but how do you configure a Web server to place multiple sites/blogs on a VPS? How to access multiple sites/domains via one IP? This is the virtual hosting feature that is supported by most Web servers. This will describe how to configure virtual hosting with Nginx step-by-step.

Nginx is a small and efficient Web server, developed by the Russian programmer Igor Sysoev, Nginx, although small, but the function is not weak, and other Web server support virtual hosting, that is, an IP corresponding to multiple domain names to support multi-site access, Just like an IP corresponds to a site, so it's "virtual". How many sites do you want to put under an IP, as long as the hard disk is large enough on the line.
Here to configure 2 sites (2 domain names) as an example, n sites can increase the adjustment accordingly,

Assume:
IP address:? 202.55.1.100
The domain name 1?example1.com?/www/example1
The domain name 2?example2.com?/www/example2

The basic ideas and steps for configuring Nginx virtual hosting are as follows:
Put 2 sites, example1.com,?example2.com? To the Nginx? Accessible directory?/www/
Create an nginx config file for each site? example1.com.conf,example2.com.conf,
And put the config file in?/etc/nginx/vhosts/
And then in the/etc/nginx.conf? include? The configuration files created in step 2 are all included (with the? * number)
Reboot? Nginx

What is the process?
The following are the specific configuration procedures:
1, create the vhosts directory under/etc/nginx
mkdir?/etc/nginx/vhosts

2, create a file named Example1.com.conf in/etc/nginx/vhosts/, and copy the following into the text
server?{
???????? Listen?? 80;
???????? server_name??example1.com?www.?example1.com;
???????? Access log?? /www/access ? example1.log?? Main
???????? Location?/? {
???????????? Root??? /www/example1.com;
???????????? Index?? index.php?index.html?index.htm;
????????}
???????? Error_page??? 500?502?503?504?? /50x.html;
???????? Location?=?/50x.html? {
???????????? Root??? /usr/share/nginx/html;
????????}
??????? #?pass?the? Php?scripts?to? fastcgi?server?listening?on?127.0.0.1:9000
???????? Location?~?. Php$? {
???????????? Fastcgi_pass??? 127.0.0.1:9000;
???????????? Fastcgi_index?? index.php;
???????????? fastcgi_param??script_filename??/www/example1.com/$fastcgi _script_name;
???????????? Include???????? Fastcgi_params;
????????}
???????? Location?~?/.ht? {
???????????? Deny?? All
????????}
}

3, in the/etc/nginx/vhosts/to create a file named Example2.com.conf, copy the following contents
Server? {
???????? Listen?? 80;
???????? server_name??example2.com?www.?example2.com;
???????? Accesslog?? /www/access? example1.log?? Main
???????? Location?/? {
???????????? Root??? /www/example2.com;
???????????? Index?? index.php?index.html?index.htm;
????????}
???????? Error_page??? 500?502?503?504?? /50x.html;
???????? Location?=?/50x.html? {
???????????? Root??? /usr/share/nginx/html;
????????}
??????? #?pass?the? Php?scripts?to? fastcgi?server?listening?on?127.0.0.1:9000
???????? Location?~?. Php$? {
???????????? Fastcgi_pass??? 127.0.0.1:9000;
???????????? Fastcgi_index?? index.php;
???????????? fastcgi_param??script_filename??/www/example2.com/$fastcgi _script_name;
???????????? Include???????? Fastcgi_params;
????????}
???????? Location?~?/.ht? {
???????????? Deny?? All
????????}
}

4, open the/etc/nginix.conf file, add in the corresponding location include the above 2 files included in
User?? Nginx
Worker_processes?? 1;
#?main?server?error?log
Error_log??????? /var/log/nginx/error.log?;
Pid????? /var/run/nginx.pid;
Events? {
???????? Worker_connections?? 1024;
}
#?main?server?config
http? {
???????? Include??????? Mime.types;
???????? Default_type?? Application/octet-stream;
???????? Log_format?? The main?? ' $remote _addr?-? $remote _user? [$time _local]? $request? '
??????????????????????‘" $status "? $body _bytes_sent?" $http _referer "?"
??????????????????????‘" $http _user_agent "?" $http _x_forwarded_for "';
???????? Sendfile???????? On
???????? #tcp_nopush????? On
???????? #keepalive_timeout?? 0;
???????? Keepalive_timeout?? 65;
???????? Gzip?? On
???????? Server? {
???????????????? Listen????????? 80;
???????????????? Servername?????;
???????????????? Access_log?????? /var/log/nginx/access.log?main;
???????????????? Server_name_in_redirect?? Off
???????????????? Location?/? {
???????????????????????? Root?? /usr/share/nginx/html;
???????????????????????? index?index.html;
????????????????}
????????}
???? #? contains all the virtual host's configuration files
???? include?/usr/local/etc/nginx/vhosts/*;
}

5. Restart Nginx
/etc/init.d/nginx?restart

Nginx_include Publishing Multiple Web sites

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.