Nginx Server settings Multiple sites use multiple profiles "Go"

Source: Internet
Author: User
Tags hosting

Nginx can be the same as other Web servers support virtual hosting, that is, an IP corresponding to multiple domain names to support multi-site access, like an IP corresponding to a site, so it is "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 are 2 sites (2 domain names) For example, n sites can increase the adjustment accordingly.

Assume:
IP Address: 202.55.1.100
Domain 1 example1.com placed in/www/example1
Domain 2 example2.com placed in/www/example2

The basic ideas and steps for configuring Nginx virtual hosting are as follows:
Put 2 sites example1.com, example2.com into the directory that Nginx can access/www/
Create an Nginx configuration file example1.com.conf,example2.com.conf for each site,
And put the configuration file in/etc/nginx/vhosts/
and add a line to the/etc/nginx.conf. Include all the configuration files created in step 2 (with * number)
Re-start Nginx

Specific Process
The following are the specific configuration procedures:
1. Create the vhosts directory under/etc/nginx

mkdir /etc/nginx/vhosts

2, in the/etc/nginx/vhosts/to create a file named Example1.com.conf, copy the following contents

Server {Listen the; 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 - 502 503 504/50x.html; Location= /50x.html {root/usr/share/nginx/html; # Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000 Location~\.php$ {fastcgi_pass127.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 the; server_name example2.com www.        example2.com; Access_log/www/Access_ Example1.log Main; Location/{root/www/example2.com;        Index index.php index.html index.htm; } error_page - 502 503 504/50x.html; Location= /50x.html {root/usr/share/nginx/html; # Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000 Location~\.php$ {fastcgi_pass127.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_processes1; # Main server error Logerror_log/var/log/nginx/error.log;p ID/var/run/nginx.pid;events {worker_connections1024x768;}        # Main server confighttp {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;        #tcp_nopush on; #keepalive_timeout0; Keepalive_timeout $; gzipOn ; server {Listen the;                server_name _; Access_log/var/log/nginx/Access.log Main;                Server_name_in_redirect off; Location/{root/usr/share/nginx/html;                Index index.html; The config file containing all the virtual hosts is included/usr/local/etc/nginx/vhosts/*;}


5. Restart Nginx

/etc/init.d/nginx restart

Reprint Address: http://www.server110.com/nginx/201309/981.html

Nginx Server settings Multiple sites use multiple profiles "Go"

Related Article

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.