Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:32:35+00:00 2026-06-08T23:32:35+00:00

I would like to host 2 different domains in the same server using Nginx.

  • 0

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 blocks, whenever I try to access second domain, it redirects to first one.

Here is my config.

server {
    listen      `www.domain1.example:80`;
    access_log  `/var/log/nginx/host.domain1.access.log`  main;
    root `/var/www/domain1`;
    server_name `www.domain1.example`;

    location ~ \.php$ {
        # Security: must set cgi.fixpathinfo to 0 in `php.ini`!
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass `127.0.0.1:9000`;
        fastcgi_index `index.php`;
        fastcgi_param SCRIPT_FILENAME         $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include `/etc/nginx/fastcgi_params`;
    }
}

server {
    listen       www.domain2.example:80;
    access_log  /var/log/nginx/host.domain2.access.log  main;
    root /var/www/domain2;
    server_name www.domain2.example;

    location ~ \.php$ {
        # Security: must set cgi.fixpathinfo to 0 in php.ini!
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME         $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include /etc/nginx/fastcgi_params;
    }
}

How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:32:37+00:00Added an answer on June 8, 2026 at 11:32 pm

    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.example;
        root /var/www/domain1;
    }
    
    server {
        listen       80;
        server_name www.domain2.example;
        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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different domains that both point to my homepage in the same
I would like to host multiple applications on the same IIS. The problem is
I would like to ping many different hosts simultaniously. Does .NET handle this concurrency
I have a server on which I am using dokuwiki to host both a
I have 2 different domains on the same server: domain1.com and domain2.com on server
I would like to host a few 3rd party PHP scripts on a Windows
I am researching a new ASP.Net project that we would like to host in
I would like to create a virtual host in apache2, but I want it
I have a GWT module with the X-GWT-Module-Base http://host:8080/foo/ and would like to call
Would like to be able to set colors of headings and such, different font

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.