1、404问题

在同一server块中,除了默认的location块外,配置一个前端工程,访问前端页面404,配置如下:

 # 官网
location / {
    root   /usr/local/nginx/html/guanwang;
    index  index.html index.htm;
}

#微信
location /wx {
    root   /usr/local/nginx/html/wx;
    index  index.html index.htm;
}

访问官网正常,访问微信404。

2、解决

2.1 alias解决

ocation中如果一个特定的url要使用别名,不能用root,alias指定的目录是准确的,root是指定目录的上级目录,改成如下即可

# 官网
location / {
    root   /usr/local/nginx/html/guanwang;
    index  index.html index.htm;
}

#微信
location /wx {
    alias   /usr/local/nginx/html/wx;
    index  index.html index.htm;
}

但是js、css、图片等静态文件出现404,需要配置,本文不涉及。

2.2 域名解决

两个域名,配置两个根目录

server {
    listen       80;
    server_name  域名A;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    # 官网
    location / {
        root   /usr/local/nginx/html/helios/dist/dist;
        index  index.html index.htm;
    }

}


server {
    listen       80;
    server_name  域名B;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    # 微信
    location / {
        root  /usr/local/openresty/nginx/html/wx;
        index  index.html index.htm;
    }

}

 

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐