There are three configuration methods for virtual hosts (commonly used for local testing, assigning an ip and port request to different application servers according to different domain names)
Not commonly used based on ip
Port-based optional
Optional based on domain name
1 #user nobody; 2 worker_processes 1 ; #The number of processes, it is best to be the same as the number of processors 3 4 #error_log logs/ error.log; #Error log print directory 5 #error_log logs/ error.log notice; 6 #error_log logs/ error.log info ; 7 8 #pid logs/ nginx.pid; #Process ip 9 10 11 events { 12 worker_connections 1024 ; #Maximum number of connections per process 13 } 14 15 16 http { 17 include mime.types; #Allow httpmime type 18 default_type application/octet-stream; #默认类型,二进制流 19 20 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 21 # '$status $body_bytes_sent "$http_referer" ' 22 # '"$http_user_agent" "$http_x_forwarded_for"'; 23 24 #access_log logs/access.log main; 25 26 sendfile on; #允许发送文件 27 #tcp_nopush on; 28 29 #keepalive_timeout 0; 30 keepalive_timeout 65 ; 31 32 # gzip on; # allow gzip compression 33 34 # default server address 35 server { 36 listen 80 ; 37 server_name localhost; 38 #charset utf- 8 ; #code 39 40 #access_log logs/ host.access. log main; 41 42 # resource address 43 location / { 44 root /home/ ftp / images; 45 index index.html index.htm; 46 } 47 48 #error_page 404 /404.html; 49 50 # redirect server error pages to the static page /50x.html 51 # 52 error_page 500 502 503 504 /50x.html; 53 location = /50x.html { 54 root html; 55 } 56 57 } 58 59 #根据端口虚拟 60 server { 61 listen 8080 ; 62 server_name localhost; 63 64 location / { 65 root html; 66 index index.html index.htm; 67 } 68 } 69 70 #Virtual 71 according to the domain name server { 72 listen 80 ; 73 server_name xxx.taotao .com; 74 75 location / { 76 root html- xxx; 77 index index.html index.htm; 78 } 79 } 80 81 server { 82 listen 80; 83 server_name yyy.taotao.com; 84 85 location / { 86 root html-yyy; 87 index index.html index.htm; 88 } 89 } 90 91 }