美文网首页
nginx子路径访问前端Vue打包项目

nginx子路径访问前端Vue打包项目

作者: 一个小前端程序员 | 来源:发表于2023-03-28 22:27 被阅读0次

1.nginx.conf配置

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8080;
        server_name  localhost;
        # 引入外部模块配置文件
        include /usr/local/nginx/conf/modules/*.conf;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

2.nginx.conf同级目录创建modules文件夹,创建[xx模块名称].conf

location /[xx路径]{
    alias /home/www/[xx文件夹]; # 子路径要用alias,不能用root
    try_files $uri $uri/ index.html =404;
    index  index.html index.htm;
}
# 代理
location /api {
      proxy_pass http://127.0.0.1:8081;
      proxy_set_header Host $http_host; #后台可以获取到完整的ip+端口号
      proxy_set_header X-Real-IP $remote_addr; #后台可以获取到用户访问的真实ip地址
}

相关文章

网友评论

      本文标题:nginx子路径访问前端Vue打包项目

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