nginx 配置

nginx html 配置

server {
    # 监听 80 端口
    listen 80;
    # 绑定域名(替换为你的实际域名)
    server_name oms.xxxxx.com;

    # 网站根目录(指向 dist 文件夹)
    root /xp/www/oms.xxxxx.com/dist;
    # 默认索引文件(前端项目通常为 index.html)
    index index.html;

    # 字符集设置
    charset utf-8;

    # 日志配置(可选,建议开启)
    access_log /var/log/nginx/oms.xxxxx.com.access.log;
    error_log /var/log/nginx/oms.xxxxx.com.error.log;

    # 处理前端路由(如 Vue Router 的 history 模式)
    location / {
        # 如果请求的文件或目录不存在,转发到 index.html
        try_files $uri $uri/ /index.html;
    }

    # 缓存静态资源(JS/CSS/图片等,可选)
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
        # 缓存有效期(根据实际需求调整,这里为 7 天)
        expires 7d;
        add_header Cache-Control "public, max-age=604800";
    }

    # 禁止访问隐藏文件(如 .git、.env 等)
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}
posted @ 2025-10-27 11:26  Lafite-1820  阅读(2)  评论(0)    收藏  举报