nginx部署vue工程和反向代理nodejs工程


前端是vue,后端是nodejs

前端打包成dist目录,后端接口是localhost:4000/api

server
    {
        listen 80;
        #listen [::]:80;
        server_name yourdomain;
        index index.html;
        root  /home/wwwroot/yourfolder/dist;

        # vue router开启了history 模式,nginx匹配不到的路由,就返回index.html,这样不报404
        location / {
                try_files $uri $uri/ /index.html;
        }
        # 反向代理
        location /api/ {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host  $http_host;
                proxy_set_header X-Nginx-Proxy true;
                proxy_set_header Connection "";
                proxy_pass  http://127.0.0.1:4000/api/;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log off;
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM