1. the content of nginx. conf is as follows:
Program code worker_processes 1;
Error_log/host/nginx/logs/error. log crit;
Pid/host/nginx/logs/nginx. pid; events {
# Network I/) model used. epoll model is recommended for Linux systems, and kqueue model is recommended for FreeBSD systems.
Use epoll;
Worker_connections 64;
} Http {
Include/host/nginx/conf/mime. types;
Default_type application/octet-stream;
# Charset gb2312;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Keepalive_timeout 60;
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 128 k;
Fastcgi_buffers' 4 128 k;
Fastcgi_busy_buffers_size 128 k;
Fastcgi_temp_file_write_size 128 k;
Client_body_temp_path/host/nginx/client_body_temp;
Proxy_temp_path/host/nginx/proxy_temp;
Fastcgi_temp_path/host/nginx/fastcgi_temp;
GzipOn;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Zip_types text/plain application/x-javascript text/css application/xml;
Gzip_varyOn;
Client_header_timeout 3 m;
Client_body_timeout 3 m;
Send_timeout 3 m;
SendfileOn;
Tcp_nopushOn;
Tcp_nodelayOn;
# Set virtual hosts
Include/host/nginx/conf/vhost/www_test_com.conf;
Include/host/nginx/conf/vhost/www_test1_com.conf;
Include/host/nginx/conf/vhost/www_test2_com.conf;
# You can also use include/host/nginx/conf/vhost/*. conf instead. wildcards are supported here.
}
========================================================== ======================================
2. create the vhost configuration file directory vhost under the conf directory, and create three corresponding www_test_com.conf, www_test1_com.conf, and www_test2_com.conf files under the vhost directory.
The configuration code for www_test_com.conf is as follows:
Server {
Listen 202. ***: 80; # Change to your IP address.
Client_max_body_size 100 M;
Server_name www.test.com; # replace it with your domain name
Charset gb2312;
Index index.html index.htm index. php;
Root/host/wwwroot/test; # your site path
# Open the Directory Browsing. if the index file is not found, the files in the directory are browsed.
AutoindexOn;
If(-D $ request_filename ){
Rewrite ^/(. *) ([^/]) $ http: // $ host/$1 $2/permanent;
}
Error_page 404/404 .html;
Location =/40x.html {
Root/host/wwwroot/test; # your site path
CharsetOn;
}
# Redirect server error pages toStaticPage/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/host/wwwroot/test; # your site path
CharsetOn;
}
# Forward client requests to fastcgi
Location ~ . * \. (Php | php5 | php4 | shtml | xhtml | phtml )? $ {
Fastcgi_pass 127.0.0.1: 9000;
Include/host/nginx/conf/fastcgi_params;
}
# Websites have many images and few changes. cache them locally in the browser for 15 days.
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Expires 15d;
}
# The website loads many JS and CSS files and caches them locally in the browser for one day.
Location ~ . * \. (Js | css )? $
{
Expires 1d;
}
Location/(WEB-INF )/{
Deny all;
}
# Set the log format
Log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
# Set access logs for the current virtual host
Access_log/host/nginx/logs/down/access. log access; # The log path, one for each virtual machine, cannot be the same
# Prevent multiple server_name problems when using nginx for web services. Click here to view the original article
Server_name_in_redirect off;
}
========================================================== ======================================
3. www_test1_com.conf and www_test2_com.conf. the file is basically the same as the above. the specific log content is as follows:
Configure www_test1_com.conf as follows:
# Set the log format
Log_format test1 '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
# Set access logs for the current virtual host
Access_log/host/nginx/logs/test1/test1.log test1; # log path, one for each virtual machine, cannot be the same
Server_name_in_redirect off;
Configure www_test2_com.conf as follows:
# Set the log format
Log_format test2 '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
# Set access logs for the current virtual host
Access_log/host/nginx/logs/test2/test2.log test2; # log path, one for each virtual machine, cannot be the same
Server_name_in_redirect off;
Virtual host configuration: http://blog.haohtml.com/archives/1222
If nginx is used as a web service, pay attention to the problems caused by multiple server_name and the solutions. Click to view