nginx——虚拟域名与多端口监听及其配置,nginx虚拟域名监听


nginx的配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       82;
        server_name  localhost;
        root D:/cardLoan/tuandai-loans/loans-web-admin/src/main/resources/web;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root D:/cardLoan/tuandai-loans/loans-web-admin/src/main/resources/web;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    alias   E:/aaa2
        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    server {
        listen       80;
        server_name  dq.aaa.cn;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
                proxy_pass    http://10.100.66.255:9007;
                proxy_redirect default ;              

        } 
      }

    #server {
        #listen       80;
        #server_name  www.aaa.cn;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        #location / {
                #proxy_pass    http://127.0.0.1:8081;
                #proxy_redirect default ;              

        #}
      #}

   server {
        listen       80;
        server_name  psjs.aaa.cn;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location /dq {
                alias   E:/psjs.aaa.cn-static/dq;
        #root   E:/td-sail-js;
                index  index.html index.htm;         

        } 
        location /scripts {
                alias   E:/psjs.aaa.cn-static/dq/scripts;
        }

        location /images {
                alias   E:/psjs.aaa.cn-static/dq/images;
        #root   E:/td-sail-js;
                index  index.html index.htm;         

        } 
      }

     server {
        listen       80;
        server_name  js2.aaa.cn;
        #root E:/aaa2/js.aaa.cn;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   E:/psjs.aaa.cn-static;
            index  index.html index.htm;
        }
    location /images {
            alias   E:/psjs.aaa.cn-static/images;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    alias   E:/aaa2
        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}

MP的配置方式
nginx.conf

# 常用命令
# 启动: nginx
# 重启: nginx -s reload
# 关闭: nginx -s stop

# 1 域名+端口 唯一确定一个资源。 nginx 可以同时监听 多个虚拟域名 和 多个端口。可以做方向代理

# 用的帐号和组,windows的直接注释掉就好了
#user  benny staff;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
    gzip_vary on;

    # 当你访问localhost时的站点配置,地址默认是d:/wwwroot
    server {
        listen       90;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;

        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # include vhosts/*.conf; # 将vhosts所有东西包含进来
    include vhosts/cardloan.dev.com.conf;

    autoindex on; #开启nginx目录浏览功能
    autoindex_exact_size off; #文件大小从KB开始显示
    autoindex_localtime on; #显示文件修改时间为服务器本地时间


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

vhost.conf

# 想建一个新站点?
# 1、复制本文件然后改名
# 2、修改root值,指向你的新站点根目录
# 3、运行nginx -s reload 重新加载配置就行了
server {
    listen  82;
    server_name  cardload.dev.com;
    root   D:/cardLoan/tuandai-loans/loans-web-admin/src/main/resources/web;
    index  index.html index.htm;

    error_page   500 502 503 504  /50x.html;

    location ~ /.ht {
        deny  all;
    }
}

网上找的 如card.dev.com.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on; 

    keepalive_timeout  65; 

    gzip  on;

    upstream localhost {
        server 127.0.0.1:8080 max_fails=7 fail_timeout=7s;
    }   
    server {
        listen       81; 
        server_name  localhost;
        location / { 
            root html;
            index index.html index.htm;
            proxy_pass http://localhost;
        }   
    }   
    server {
        listen       80; 
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / { 
            root   html;
            index  index.html index.htm;
            proxy_pass http://localhost;
        }
    }
}
版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/longlc123/article/details/79127825

相关内容

    暂无相关文章