美文网首页
vue生产环境部署

vue生产环境部署

作者: 王玩玩 | 来源:发表于2018-12-04 17:05 被阅读0次

    vue生产环境部署

    • Nginx部署静态资源文件和解决跨域问题
      • 下载Nginx

        下载地址:http://nginx.org/en/download.html
        下载后解压到指定目录

      • 配置

        打开 ‘nginx根目录/conf/’ nginx.conf 文件进行配置

        #35行开始
        server {
            #监听的端口
            listen       80;
            #接收请求的ip或域名
            server_name  localhost 127.0.0.1;
            location / {
                #配置静态文件路径
                root   user/build/rsm-app;
                index  index.html index.htm;
                #解决跨域问题配置
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET';
            }
            #匹配规则,进行转发请求
            #将所有api的url请求进行转发
            location ^~/api/{
                #rewrite ^/(.*)$ /$1 break;
                #后台接口地址
                proxy_pass   http://127.0.0.1:8080;
            }
        }
        
      • 启动/重启 Nginx

        启动代码格式:nginx安装目录地址 -c nginx配置文件地址

        启动: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

    相关文章

      网友评论

          本文标题:vue生产环境部署

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