Here to configure 2 sites (2 domain names) For example, n sites can be adjusted accordingly, assuming:
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 profile example1.com.conf,example2.com.conf for each site and place 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 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 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, create a file named Example2.com.conf in/etc/nginx/vhosts/, and copy the following into the
server {Listen 80; 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 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 include in the appropriate location to include the above 2 files in the
User nginx;worker_processes 1;# Main server error Logerror_log/var/log/nginx/error.log;p id/var/run/nginx.pid;events { Worker_connections 1024;} # 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_timeout 0;keepalive_timeout 65;gzip On;server {Listen 80; server_name _; 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 file include/usr/local/etc/nginx/vhosts/*;}
5. Restart Nginx
/etc/init.d/nginx restart
How to configure multiple sites under Nginx server