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