美文网首页
服务代理

服务代理

作者: 撑船的摆渡人 | 来源:发表于2019-06-24 10:40 被阅读0次

下载好nginx包,进行解压安装。
修改 conf 文件夹下面的 nginx.conf 文件


#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       8090;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        # location / {
        #     root   html;
        #     index  index.html index.htm;
        # }
        location   /images/ {
            alias /;
        }
        location /managePlat/ {
            alias   I:/html/;
        }

        location /manage-api/images/ {
            proxy_pass  http://0.0.0.0:9030/images/;
            client_max_body_size  100m;
        }

        location /manage-api/ {
            proxy_pass  http://0.0.0.0:9010/;
            client_max_body_size  100m;
        }


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

}

配置完成后,在浏览器中输入 http://0.0.0.0:9030/managePlat/index.html
就可以直接访问之前我们打包的项目了,里面的请求也可以正常请求了
这块的配置相当于我们在项目中 config 文件夹下面的 index.js

'use strict'
// Template version: 1.2.6
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

module.exports = {
  dev: {
    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/mock': {
        target: 'http://0.0.0.0:2294/', // RAP地址
        pathRewrite: {
          '^/mock': '/mockjsdata/38' // 运营管理平台mock数据
        }
      },
      '/manage-api/filesapi': {
        target: 'http://0.0.0.0:98/', // 文件下载服务器
        pathRewrite: {
          '^/manage-api/filesapi': '' // 运营管理平台文件下载服务器接口前缀
        }
      },
      '/manage-api/images': {
        target: 'http://0.0.0.0:9030/images/', // 图片回显服务器地址
        changeOrigin: true,
        pathRewrite: {
          '^/manage-api/images': '' // 图片回显接口前缀
        }
      },
      '/manage-api': {
        target: 'http://0.0.0.0:9010/', // 云服务器地址
        changeOrigin: true,
        pathRewrite: {
          '^/manage-api': '/' // 运营管理平台接口前缀
        }
      },
      '/api': {
        target: 'http://0.0.0.0:8080/', // 请求后台本地地址
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    },
    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 9926, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: true,
    errorOverlay: true,
    notifyOnErrors: false,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: true,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-source-map', //  在cheap-source-map模式下sourcemap不包含列信息,从loaders生成的sourcemap没有被使用

    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  },
}

相关文章

  • nginx

    # 代理类型 * 正向代理服务器 代理服务器位于客户端 * 反向代理服务器 代理服务器位于服务端

  • Nginx实现负载均衡

    1.什么是反向代理 正向代理,反向代理正向代理:客户端知道服务端,通过代理端连接服务端。代理端代理的是服务端。 反...

  • Nginx核心概念

    1.HTTP代理和反向代理 代理服务和反向代理服务是Nginx服务器作为Web服务器的主要功能之一,尤其是反向代理...

  • 设计模式——代理模式

    静态代理 简单实现 1、服务接口 2、服务实现类 3、服务的抽象代理类 4、服务的具体代理类 5、实现代理过程 为...

  • 利用Nginx实现反向代理和负载均衡

    什么是反向代理? 正向代理(基于客户端的代理) 反向代理(基于服务器端的代理) 反向代理服务器决定哪台服务器提供服...

  • requests深入

    代理 浏览器 --> 服务器反向代理:浏览器 --> nginx --> 服务器正向代理:浏览器 --> 代理 ...

  • Nginx-代理服务

    目录章节 代理示意图 Nginx代理服务 配置语法及反向代理场景 代理示意图 Nginx代理服务 如图所示 翻墙-...

  • 正向代理和反向代理

    参考反向代理为何叫反向代理? 正向代理 用户想要通过代理服务器访问外部的服务器. 主机先将请求发送到代理服务器, ...

  • 「爬虫」08爬虫防屏蔽手段之代理服务器

    1.代理服务器 代理服务器是处于用户与互联网中间的服务器,浏览信息时,用户先向代理服务器发出请求,然后代理服务...

  • 代理与反向代理

    代理(代理服务器) 什么是代理服务器(Proxy Server) 代理服务器是一种重要的服务器安全功能,它的工作主...

网友评论

      本文标题:服务代理

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