美文网首页
Nginx部署vue项目配置

Nginx部署vue项目配置

作者: Mracale | 来源:发表于2024-01-03 13:57 被阅读0次

    Nginx部署vue项目配置

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        root /var/www/html;
    
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    
        server_name _;
    
        location /{
            try_files $uri $uri/ @router;   #重点:必须设置,不然会导致刷新时页面找不到,造成404
            index  index.html index.htm;
        }
        location @router{                   #重点:这里用来进行重写操作, 对应上面的@router
            rewrite ^.*$ /index.html last;
        }
        location ~* \.(css|js)$ {
              gzip_static on; #可选
        }
        location ~ ^/api/ {                        #可选: api转发,转发到你的api发布地址
             rewrite ^/api/(.*)$ /$1 break;
             proxy_pass http://127.0.0.1:7001;
        }
    }
    
    
    
    

    相关文章

      网友评论

          本文标题:Nginx部署vue项目配置

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