NGINX反向代理 tocat

打开ubuntu 在命令行敲ifconfig 把虚拟机 ip 地址整出来

在windows C:\Windows\System32\drivers\etc 找到hosts文件加上端口号 和域名

192.168.244.131  aa.ln.com(这是我的!)

打开ubuntu 找到/usr/local/Tengine/conf/nginx.conf文件

 
#user  nobody;
#剪切工具必须要root用户才有权限使用
user  root;
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;
}
 
# load modules compiled as Dynamic Shared Object (DSO)
#
#dso {
#    load ngx_http_fastcgi_module.so;
#    load ngx_http_rewrite_module.so;
#}
 
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 itrip{
        server 192.168.1.12:8080;#拦截
    }

    server {
        listen       80;
        server_name  localhost;
          root   html;
                index  index.html index.htm;
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
      
  location / {
           proxy_pass http://itrip;
        }

    #这里我是拦截/pic即网络访问路径是 localhost/pic
    location /pic {
          #也可以使用alias,alias就不会将拦截路径自动添加进来。
      #root比较鬼畜,它会将你上面配置的拦截自动加到路径内,即 localhost/demo/pic  demo文件是我直接放在nginx下的详细路径是/usr/local/Tengine/demo/pic/
      root   demo/;
      #我的首页放在/usr/local/Tengine/demo/pic/index.html,测试的图片与其同级!
      index  index.html;
          expires 1h;    # 缓存时间
          add_header Cache-Control max-age=3600; # 缓存时间
          access_log   /var/log/Tengine/host_access.log;
    }
 
    #配置拦截图片后缀的请求,开始作用图片剪切工具
        #如果 url 格式如:xxxx.gif_数字x数字.gif
        location ~* ^(.+\.(jpg|jpeg|gif|png))_(\d+)x(\d+)\.(jpg|jpeg|gif|png)$ {
    #这里必须设置,找不到要剪切文件的路径,如:图片所在路径是/usr/local/Tengine/demo/pic/1.jpg 必须要先指定根目录在哪,否则你在var/log/nginx/error文件里面看报错的路径来调了
           root demo;
           if (!-f $request_filename) { #如果文件不存在时才需要裁剪
              add_header X-Powered-By 'Lua GraphicsMagick';  #此HTTP Header无实际意义,用于测试
              add_header file-path $request_filename;  #此 HTTP Header无实际意义,用于测试
              lua_code_cache on;  #在编写外部 Lua脚本时,设置为off Nginx不会缓存 Lua,方便调试
              set $request_filepath /usr/local/Tengine/demo$1;  #设置被剪切的图片文件地址(到图片的文件夹)
              set $width $3;     # 设置裁剪/缩放的宽度
              set $height $4;    # 设置裁剪/缩放的高度
              set $ext $5;      # 图片文件格式后缀
              content_by_lua_file /usr/local/Tengine/lua/ImageResizer.lua;  #加载外部 Lua 文件,就是上面配置的ImageResizer.lua,作用是执行图片剪切工具的脚本
            }
        }
 
        #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;
        }
    }
}

关闭nginx服务;重新启动,windows访问aa.ln.com

猜你喜欢

转载自blog.csdn.net/madehaiyoushei/article/details/83822044