美文网首页
007--Window使用Nginx

007--Window使用Nginx

作者: 糖纸疯了 | 来源:发表于2020-02-04 13:14 被阅读0次

1、写在前面

因为nginx是常用的负载均衡,在linux上有时只暴露80端口,但是linux有时需要安装很多服务,所有需要用nginx进行服务暴露,特别是docker


2、核心操作


3、具体操作

3.1、window安装nginx

  • 直接解压到指定的文件夹即可

3.2、启动nginx

  • 双击nginx.exe接口(如果页面一闪而过就代表成功)
  • 如果启动报错,可以查看logs里面的具体内容
  • 访问页面:localhost

3.3、多服务负载




#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;
    
    upstream mytomcat {   
      server 127.0.0.1:8082 weight=1;
      server 127.0.0.1:8083 weight=2;
      server 127.0.0.1:8084 weight=1;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           proxy_pass  http://mytomcat;
        }
        
        #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;
        }
    }

}
  • 修改地方如下:
  • 此时刷新就可以成功负载


3.3、多服务负载

  • 根据域名进行多服务负载

#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;
    
    upstream mytomcat1 {   
      server 127.0.0.1:8082 weight=1;
      server 127.0.0.1:8084 weight=1;
    }
    upstream mytomcat2 {   
      server 127.0.0.1:8083;
    }

    server {
        listen       80;
        server_name  www.enzo.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        
        #proxy_set_header X-Forwarded-Host $host;
        #proxy_set_header X-Forwarded-Server $host;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location /a/ {
           proxy_pass  http://mytomcat1/;
        }
        
        location /b/ {
           proxy_pass  http://mytomcat2/;
        }
        
        #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;
        }
    }
}
  • 前提是我在host上配置了:



相关文章

  • 007--Window使用Nginx

    1、写在前面 因为nginx是常用的负载均衡,在linux上有时只暴露80端口,但是linux有时需要安装很多服务...

  • 贵安项目nginx配置

    关于nginx的使用以及为什么使用【Nginx】什么是Nginx?为什么使用Nginx?nginx 之 proxy...

  • brew下安装并且使用nginx

    使用 brew search nginx命令,搜索nginx 使用 brew install nginx命令,安...

  • mac 配置Nginx服务

    安装nginx brew install nginx安装后使用nginx -v查看nginx版本 配置nginx ...

  • Nginx作为代理服务

    一. 为什么使用Nginx 要回答为什么要使用nginx,那就先说说nginx能做些什么。首先,nginx能做反向...

  • nginx: [emerg] bind() to 0.0.0.0

    使用systemctl start nginx启动nginx失败, 使用systemctl status ngin...

  • Docker Nginx的使用

    Docker Nginx的使用 使用dockerfile定制nginx镜像新建一个目录t-nginx sudo m...

  • Tomcat

    方案二: Nginx+Tomcat方案三: 使用nginx做反向代理负载均衡 建议使用Nginx和Tomca...

  • 【Docker 系列】docker 学习 三

    【Docker 系列】docker 学习 三 使用 Dcoker 部署 nginx 搜索 nginx 镜像 使用 ...

  • nginx与uWsgi

    什么是nginx 为什么使用nginx nginx、WSGI、uwsgi、uWSGI nginx和uWSGI 的意...

网友评论

      本文标题:007--Window使用Nginx

      本文链接:https://www.haomeiwen.com/subject/phcrxhtx.html