欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue打包使用Nginx代理解決跨域問(wèn)題

 更新時(shí)間:2018年08月27日 10:24:32   作者:漫步星空Z(yǔ)L  
這篇文章主要介紹了vue打包使用Nginx代理解決跨域問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

vue 在開(kāi)發(fā)環(huán)境,涉及跨域,就在本地配置了代理,但是部署到服務(wù)器上,就不行了。

解決方法有一下幾種

  • 服務(wù)器端配置CORS
  • 用nginx反向代理,和訪(fǎng)問(wèn)本地服務(wù)器是一樣的
  • 可以修改成正式線(xiàn)上的地址,再build

推薦

使用nginx配置反向代理,這樣就可以在前端徹底解決跨域問(wèn)題。

vue index.js文件源碼

'use strict'
// Template version: 1.2.7
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
changeOrigin: true,
proxyTable: {
'/api': {
target: 'https://api.it120.cc/fengyu',
changeOrigin:true,
pathRewrite: {
'^/api': ''
}
},
'/book': {
target: 'http://api.zhuishushenqi.com/',
changeOrigin:true,
pathRewrite: {
'^/book': ''
}
},
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
// 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,
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: './static',
assetsPublicPath: './',
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}

Nginx 配置文件源碼

# power by www.php.cn
#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;
  #tcp_nodelay on;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 128k;
 fastcgi_buffers 4 128k;
 fastcgi_busy_buffers_size 256k;
 fastcgi_temp_file_write_size 256k;
 #gzip on;
 gzip on;
 gzip_min_length 1k;
 gzip_buffers   4 32k;
 gzip_http_version 1.1;
 gzip_comp_level 2;
 gzip_types    text/plain application/x-javascript text/css application/xml;
 gzip_vary on;
 gzip_disable "MSIE [1-6].";
 server_names_hash_bucket_size 128;
 client_max_body_size   100m; 
 client_header_buffer_size 256k;
 large_client_header_buffers 4 256k;
  server {
    listen    80;
    server_name localhost;
    #charset koi8-r;
    #access_log logs/host.access.log main;
    root  "E:/phpStudy/PHPTutorial/WWW";
    location / {
      index index.html index.htm index.php l.php;
      autoindex off;
    }
    #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(.*)$ {
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
      include    fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #  deny all;
    #}
location /api {
proxy_pass https://api.it120.cc/fengyu;
} 
  }
  # 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;
  #  server_name localhost;
  #  ssl         on;
  #  ssl_certificate   cert.pem;
  #  ssl_certificate_key cert.key;
  #  ssl_session_timeout 5m;
  #  ssl_protocols SSLv2 SSLv3 TLSv1;
  #  ssl_ciphers HIGH:!aNULL:!MD5;
  #  ssl_prefer_server_ciphers  on;
  #  location / {
  #    root  html;
  #    index index.html index.htm;
  #  }
  #}
include vhosts.conf;
}

成功截圖


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue.js每天必學(xué)之組件與組件間的通信

    Vue.js每天必學(xué)之組件與組件間的通信

    Vue.js每天必學(xué)之組件與組件間的通信,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • vue的自定義指令傳參方式

    vue的自定義指令傳參方式

    這篇文章主要介紹了vue的自定義指令傳參方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Electron自動(dòng)更新失效報(bào)錯(cuò)Error:?Object?has?been?destroyed的問(wèn)題解決

    Electron自動(dòng)更新失效報(bào)錯(cuò)Error:?Object?has?been?destroyed的問(wèn)題解決

    本文主要講解如何解決?Error:?Object?has?been?destroyed?這個(gè)?Electron?中最常見(jiàn)的問(wèn)題,以及?Electron?自動(dòng)更新的流程,文中通過(guò)代碼示例給大家講解的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • vue3如何使用ref獲取元素

    vue3如何使用ref獲取元素

    這篇文章主要介紹了vue3如何使用ref獲取元素,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • vue 如何實(shí)現(xiàn)表單校驗(yàn)

    vue 如何實(shí)現(xiàn)表單校驗(yàn)

    這篇文章主要介紹的是vue 如何實(shí)現(xiàn)表單校驗(yàn)的方法,又代碼詳細(xì)解說(shuō),感興趣的小伙伴可以參考下面文章的具體內(nèi)容
    2021-09-09
  • Element Alert警告的具體使用方法

    Element Alert警告的具體使用方法

    這篇文章主要介紹了Element Alert警告的具體使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • vue.js動(dòng)畫(huà)中的js鉤子函數(shù)的實(shí)現(xiàn)

    vue.js動(dòng)畫(huà)中的js鉤子函數(shù)的實(shí)現(xiàn)

    這篇文章主要介紹了vue.js動(dòng)畫(huà)中的js鉤子函數(shù)的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • Vue與.net?Core?接收List<T>泛型參數(shù)

    Vue與.net?Core?接收List<T>泛型參數(shù)

    這篇文章主要介紹了Vue與.net?Core?接收List<T>泛型參數(shù),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-04-04
  • 打包組件報(bào)錯(cuò):Error:Cannot?find?module?'vue/compiler-sfc'

    打包組件報(bào)錯(cuò):Error:Cannot?find?module?'vue/compiler-sfc&ap

    最近遇到這樣的問(wèn)題,vue組件庫(kù)搭建過(guò)程中使用webpack打包組件時(shí)報(bào)錯(cuò),本文給大家分享打包組件報(bào)錯(cuò):Error:?Cannot?find?module?‘vue/compiler-sfc‘的解決方法,感興趣的朋友一起看看吧
    2023-12-12
  • tomcat部署前端vue項(xiàng)目步驟(項(xiàng)目上線(xiàn)具體操作)

    tomcat部署前端vue項(xiàng)目步驟(項(xiàng)目上線(xiàn)具體操作)

    在實(shí)際開(kāi)發(fā)中,我們經(jīng)常會(huì)遇到將Vue項(xiàng)目部署到Tomcat服務(wù)器上的需求,下面這篇文章主要給大家介紹了關(guān)于tomcat部署前端vue項(xiàng)目(項(xiàng)目上線(xiàn)具體操作)的相關(guān)資料,需要的朋友可以參考下
    2024-07-07

最新評(píng)論