zoukankan      html  css  js  c++  java
  • Nginx*-端口转发与目录转发

    一、配置

    nginx.conf中引入include vhost/*.conf;配置文件
    在nginx.conf同级目录下创建vhost/port.conf文件

    二、端口转发

    server {
        listen 80;
        autoindex on;
        server_name www.port.com;
        access_log c:/access.log combined;
        index index.html index.htm index.jsp index.php;
        #error_page 404 /404.html;
        if ( $query_string ~* ".*[;'<>].*" ) {
            return 404;
        }
    
        location / {
            proxy_pass http://127.0.0.1:8080;
            add_header Access-COntrol-Allow-Origin *;
        }
    }
    

    配置hosts
    127.0.0.1 www.port.com
    重启Nginx
    niginx -s reload
    http://127.0.0.1:8080端口是配置的tomcat服务器
    这样当输入www.port.com时就会转发到tomcat服务器啦

    二、文件转发

    server {
        listen 80;
        autoindex on;
        server_name www.file.com;
        access_log c:/access.log combined;
        index index.html index.htm index.jsp index.php;
        #error_page 404 /404.html;
        if ( $query_string ~* ".*[;'<>].*" ) {
            return 404;
        }
    
        location / {
            root C:fileimg; # 是Windows /是Linux
            add_header Access-Control-Allow-Origin *;
        }
    }
    
    

    配置hosts
    127.0.0.1 www.file.com
    重启Nginx
    niginx -s reload
    访问 www.file.com 就可以看到C:fileimg下的图片。

  • 相关阅读:
    Java自学
    java自学
    Java自学
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
  • 原文地址:https://www.cnblogs.com/greycdoer0/p/11817274.html
Copyright © 2011-2022 走看看