美文网首页
nginx结合vue+node简单配置

nginx结合vue+node简单配置

作者: litielongxx | 来源:发表于2019-07-08 13:52 被阅读0次

根目录部署vue打包dist

vue项目打包为dist,默认访问服务器绑定的域名,需要配置80端口,配置位置多默认为cd /usr/local/nginx/cong下的nginx.conf。

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main (node_demo为node后台下public);

        location / {
            root   /home/node_demo/public/;
            index  index.html;
        }

      #配置实列接口访问
        location /api {
            proxy_pass http://127.0.0.1:3000/api;
             proxy_set_header Host $proxy_host;
        }

      #配置后台数据界面 (vue项目nginx部署到非根目录下空白刷新)
        location ^~/adm {
            alias /home/adm;
            try_files $uri $uri/ /adm/index.html;
        }

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

备注:

非根目录需要alias配置路径
非根目录nginx刷新空白需要try_files配置刷新时公用的index.html
node的静态资源结合dist可以直接放到public下

相关文章

网友评论

      本文标题:nginx结合vue+node简单配置

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