zoukankan      html  css  js  c++  java
  • nginx 方向代理

    #nginx 监听原理 先监听端口 --> 再配置域名 -->匹配到就访问local 否则 没有匹配到域名就默认访问第一个监听端口的local地址

    # vi nginx.conf
    user nobody nobody; # 运 nginx的所属组和所有者
    worker_processes 2; # 开启两个 nginx工作进程,一般几个 CPU核心就写几
    error_log logs/error.log notice; # 错误日志路径
    pid logs/nginx.pid; # pid 路径
    events {
    worker_connections 1024; # 一个进程能同时处理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;
      keepalive_timeout 65; # keepalive超市时间
      # 开始配置一个域名,一个server配置段一般对应一个域名
      server {
        listen 80; # 监听端口()
        # 在本机所有ip上监听80,也可以写为192.168.1.202:80,这样的话,就只监听192.168.1.202 上的80口
        server_name www.heytool.com; # 域名
        root /www/html/www.heytool.com; # 站点根目录(程序目录)
        index index.html index.htm; # 索引文件

        # 可以有多个 location
        location / {
          #proxy_pass www.baidu.com # 跳到 百度页面 (网址)
          root /www/html/www.heytool.com; # 站点根目录(程序目录) (本地的路径)
        }

        error_page 500 502 503 504 /50x.html;
        # 定义错误页面,如果是500错误,则把站点根目录下的50x.html返回给用户
        location = /50x.html {
        root /www/html/www.heytool.com;
      }
    }

    nginx 服务器重启命令,关闭

     Windows下Nginx的启动、停止等命令
    在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动、停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍。
    1、启动:
    C:server ginx-1.0.2>start nginx或
    C:server ginx-1.0.2>nginx.exe
    nginx -s reload  :修改配置后重新加载生效
    nginx -s reopen  :重新打开日志文件
    nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

    关闭nginx:
    nginx -s stop  :快速停止nginx
             quit  :完整有序的停止nginx

    其他的停止nginx 方式:

    --   定义 zyh.conf

    upstream ioob.com {
    server localhost:8888;
    }
    upstream tomcatserver2 {
    server 192.168.72.49:8082;
    }
    server {
    listen 8089;
    server_name 8081.max.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    proxy_pass http://ioob.com;
    index index.html index.htm;
    }
    }

    --  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;
    include zyhconfig/*.conf;
    #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 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root html;
    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 {
    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;
    #}
    }


    # 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;
    # }
    #}

    }

  • 相关阅读:
    【不错的文章收藏了】我的Delphi开发经验谈
    【转载】Delphi异常处理try except语句和try finally语句用法以及区别
    Asp防止网页频繁刷新和强制不缓存的方法
    JavaScript的document和window对象详解
    Delphi下获取系统默认的UserAgent的方法
    【转载】ACCESS技巧集(DELPHI AND SQL)
    c#中const与readonly区别
    C#中virtual 方法和abstract方法的区别
    static(C# 参考)
    按键精灵
  • 原文地址:https://www.cnblogs.com/javajetty/p/9657309.html
Copyright © 2011-2022 走看看