Nginx Different Domains on Same IP

前端 未结 1 1340
逝去的感伤
逝去的感伤 2020-11-29 15:11

I would like to host 2 different domains in the same server using nginx. I redirected both domains to this host via @ property. Although I configure 2 different server block

相关标签:
1条回答
  • 2020-11-29 16:08

    Your "listen" directives are wrong. See this page: http://nginx.org/en/docs/http/server_names.html.

    They should be

    server {
        listen      80;
        server_name www.domain1.com;
        root /var/www/domain1;
    }
    
    server {
        listen       80;
        server_name www.domain2.com;
        root /var/www/domain2;
    }
    

    Note, I have only included the relevant lines. Everything else looked okay but I just deleted it for clarity. To test it you might want to try serving a text file from each server first before actually serving php. That's why I left the 'root' directive in there.

    0 讨论(0)
提交回复
热议问题