全国咨询热线:18720358503

微信如何创建小程序_vue打包使用Nginx代了解决跨

类别:媒体报道 发布时间:2021-01-08 浏览人次:

vue打包使用Nginx代理解决跨域问题       这篇文章主要介绍了vue打包使用Nginx代理解决跨域问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

vue 在开发环境,涉及跨域,就在本地配置了代理,但是部署到服务器上,就不行了。

解决方法有一下几种

服务器端配置CORS 用nginx反向代理,和访问本地服务器是一样的 可以修改成正式线上的地址,再build

推荐

使用nginx配置反向代理,这样就可以在前端彻底解决跨域问题。

vue index.js文件源码

'use strict'
// Template version: 1.2.7
// see webpack for documentation.
const path = require('path')
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
changeOrigin: true,
proxyTable: {
'/api': {
target: 'fengyu',
changeOrigin:true,
pathRewrite: {
'^/api': ''
'/book': {
target: '',
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, // configuration/dev-server/#devserver-watchoptions-
* Source Ma凡科抠图
// configuration/devtool/#development
devtool: 'eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// #cachebusting
cacheBusting: true,
// CSS Sourcema凡科抠图 off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (webpack/css-loader#sourcema凡科抠图)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false,
build: {
// 
index: path.resolve(__dirname, '../'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: './static',
assetsPublicPath: './',
* Source Ma凡科抠图
productionSourceMap: true,
// 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 --pression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run mand 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 
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/;
#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;
 p_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.htm index.php l.php;
 autoindex off;
 #;
 # 
 ;
  {
 root html;
 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 #location ~ \.php$ {
 # proxy_pass  .+)$;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_param PATH_INFO $;
 fastcgi_param PATH_TRANSLATED $;
 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 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.htm;
 # HTT凡科抠图 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.htm;
include vhosts.conf;

成功截图


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持凡科。


推荐阅读

微信如何创建小程序_vue打包使用Nginx代了解决跨

vue装包应用Nginx代理商处理跨域难题 本文关键详细介绍了vue装包应用Nginx代理商处理跨域难题,网编感觉挺好的,如今共享给大伙儿,也给大伙儿做下参照。一起追随网编回来看一...

2021-01-08
软文快速推广的四大技巧!

7*二十四小时为您服务解释:seo优化,企业网站建设,APP开发设计,微信小程序开发设计,H5开发设计,知名品牌营销推广,新闻报道营销推广,网络舆情检测等十分谢谢您有细心的念完本文:"推...

2021-01-08
微信小程序开发的步骤-深圳微信小程序开发要多

深圳市微信小程序开发设计是多少钱?要考虑到什么难题?33深圳市微信小程序开发设计是多少钱?必须的花费就是包含了五个层面,也便是大家常常常说的,前端开发+后端开发+网络服务器...

2021-01-08
网站优化之百度收录数量不稳定的原因

seo优化之百度搜索百度收录总数不平稳的缘故创作者:1.网站的內容2.网站是不是出現了比较敏感词百度搜索是中国的较大的搜索模块,也是应用数最多的检索模块,因此有许多的文本不...

2021-01-08
小程序商城优势_微信小程序完成列表页的点赞和

手机微信微信小程序完成目录页的关注和撤销关注作用 本文关键为大伙儿详尽详细介绍了手机微信微信小程序完成目录页的关注和撤销关注作用,具备一定的参照使用价值,很感...

2021-01-08
什么是定制网站?

什么叫订制网站订制网站就是指对于公司开展再次方案策划、计划方案撰写、再次设计方案、再次作用开发设计的网站建设,说的简易一点,便是依据公司的商品特性、宣传策划营销推...

2021-01-08
X

400-8700-61718720358503
企业邮箱2639601583@qq.com
官方微信