关于nginx反向代理转发

服务器绑定两个域名www.domain.com,m.domian.com
静态文件在/wwwroot/wwwroot/default/staitc/下,静态文件地址都是相对地址,导致m.domian.com无法访问静态文件

/static/images/2017/a.jpg
正常http://www.domain.com/static/images/2017/a.jpg
404错误http://m.domain.com/static/images/2017/a.jpg 

我想用nginx转发,但是不成功

server
{
    listen 80;
    server_name www.domain.com;
    index index.php index.html;
    root /wwwroot/wwwroot/default;

    error_page 404 /404.html;
    error_page 502 /502.html;

    include enable-php-56.conf;

}

server
{
    listen 80;
    server_name m.domain.com;
    index index.php index.html;
    root /wwwroot/wwwroot/default/m;
     
    location /static/ {
        proxy_pass http://www.domain.com/static/;
    }
}

/wwwroot/wwwroot/default/m/下只有

/wwwroot/wwwroot/default/m/index.php
/wwwroot/wwwroot/default/m//template/

访问http://m.domain.com/static/返回404

在/wwwroot/wwwroot/default/m/目录下创建/static/目录,访问http://m.domain.com/static/就能正常转发到http://www.domain.com/static/

问题1:nginx转发只能是静态文件转静态文件吗?
问题2:只能转发/m/目录下存在的文件吗?
问题3:我要怎配置才能正常转发?

阅读 2.4k
1 个回答
server
{
    listen 80;
    server_name m.domain.com;
    index index.php index.html;
    root /wwwroot/wwwroot/default/m;
     
    location /static/ {
        alias /wwwroot/wwwroot/default/static/;
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题