当前位置: 首页 >服务端 > nginx配置vue项目,带项目名

nginx配置vue项目,带项目名

项目是前后端分离的,vue部署到生产环境时需要带项目名进行访问。acdmSA是我的项目名。

一、修改vue项目config/index.js中的build配置

  assetsPublicPath:'/',改为assetsPublicPath:’/acdmSA/'。

nginx配置vue项目,带项目名 _ JavaClub全栈架构师技术笔记

二、修改router配置,src/router/index.js中修改router

增加base:'/acdmSA/' 

nginx配置vue项目,带项目名 _ JavaClub全栈架构师技术笔记

 三、打包,上传到服务器

npm run build

压缩成zip,上传到目录:/home/datastatistics-front ,解压:unzip dist.zip。如下图:

nginx配置vue项目,带项目名 _ JavaClub全栈架构师技术笔记

四、nginx配置

 

worker_processes  4;#error_log  logs/error.log  info;#pidlogs/nginx.pid;error_log  /var/log/nginx/error.log  info; pid/run/nginx.pid;events {use epoll;worker_connections  1024;}http {includemime.types;default_type  application/octet-stream;log_format log_access '$remote_addr - $remote_user [$time_local] "$request" $http_host '  '$status $body_bytes_sent "$http_referer" '  '"$http_user_agent" "$http_x_forwarded_for" '  '"$upstream_addr" "$upstream_status" $upstream_cache_status "$upstream_http_content_type" "$upstream_response_time" > $request_time ' ;#access_log logs/access.log log_access;server_tokens off;sendfile on;tcp_nopush on;tcp_nodelay on;client_body_timeout  20;client_header_timeout 20;keepalive_timeout  3000;send_timeout20;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;client_max_body_size 800m;client_body_buffer_size  2048k;client_header_buffer_size 32k;server_names_hash_bucket_size 2048;server_names_hash_max_size 1024;proxy_connect_timeout60;proxy_read_timeout300;proxy_send_timeout300;proxy_buffer_size  16k;proxy_buffering on ;proxy_buffers4 64k;proxy_busy_buffers_size 128k;proxy_max_temp_file_size 1024m;proxy_temp_file_write_size 128k;proxy_headers_hash_max_size 512;proxy_headers_hash_bucket_size 256;gzip on;gzip_min_length  1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_typestext/plain application/x-javascript text/css application/xml application/javascript  application/octet-stream;gzip_vary on;server {listen8089;server_name  localhost 111.74.186.13;location /datastatistics {  proxy_set_header Host $host:$server_port;  proxy_set_header X-Real-IP $remote_addr;  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  proxy_pass http://111.74.186.13:18080/;  client_max_body_size 10m;}location /acdmSA {alias  /home/datastatistics-front/dist/;index  index.html index.htm;try_files $uri $uri/ /index.html =404;}error_page500 502 503 504  /50x.html; location = /50x.html {roothtml;} }}

这里重点关注 location /acdmSA 的配置即可。 location /datastatistics是后端接口服务。

访问:111.74.186.13:8089/acdmSA  。

我的nginx用docker启动的。在这里不再赘述。

 

作者:FinelyYang
来源链接:https://blog.csdn.net/xiaoxiangzi520/article/details/103793197

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/server/112123.html

标签:Nginx
分享给朋友:

“nginx配置vue项目,带项目名” 的相关文章