Nginx多域名映射到对应不同tomcat的nginx.conf配置详解

废话不多说,直接上干货,下面是一个完整的nginx.conf的配置信息:

user nginx;
worker_processes  1;

error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log  notice;
#error_log /var/log/nginx/error.log  info;

pid       /var/run/nginx.pid;

events {
   worker_connections  1024;
}

http {
   include      /etc/nginx/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"';

   access_log /var/log/nginx/access.log  main;

   sendfile       on;
   #tcp_nopush    on;

   #keepalive_timeout  0;
   keepalive_timeout  65;

   #gzip  on;

    # Loadmodular configuration files from the /etc/nginx/conf.ddirectory.
    # Seehttp://nginx.org/en/docs/ngx_core_module.html#include
    # for moreinformation.
    include/etc/nginx/conf.d/*.conf;

    upstreamdruid {
       server 127.0.0.1:8090;
   }

upstream yunbang {
       server 127.0.0.1:8091;
    }

    upstreamsanji {
       server 127.0.0.1:8090;
    }

    server{
       listen      80;
       server_name  www.druid.com druid.commonitor.druid.com;
       root  /usr/local/tomcat7-big/webapps;
       location / {
         proxy_pass http://druid;
         proxy_set_header  Host   $host;
         proxy_set_header  X-Real-IP   $remote_addr;
         proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
       }
    }

    server{
       listen      80;
       server_name  www.yunbang.com yunbang.com;
       root  /usr/local/tomcat7-yun/webapps;
       location / {
         proxy_pass http://yunbang;
         proxy_set_header  Host   $host;
         proxy_set_header  X-Real-IP   $remote_addr;
         proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
       }
    }
    server{
       listen      80;
       server_name  www.sanji.com sanji.com;
        root  /usr/local/tomcat7-big/webapps;

你可能感兴趣的:(linux)