0

I have 2 domain connected to my server IP. Files for one domain are in /var/www/firstdomain.com folder, files for the second are in /var/www/seconddomain.com folder.

I would like to process the first domain by nginx and the second domain by apache without port changes, they both should be run on 80 port.

I tried to set firstdomain:80 to listen option for Apache and seconddomain:80 option for nginx, but it seeems that such configuration does not work, because they still are using the same port.

I think that the right way is to use nginx as main server and proxyfy all requests that go to seconddomain.com to apache, but cannot find how can I do this. I tried to run Apache on 8080, but don't know what shall I add to location statement to make in work:

location {?????} {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        proxy_set_header Host $host;

        proxy_pass http://127.0.0.1:8080;
  }

I also tried to do

server {
  listen 80 default;

  root /var/www/seconddomain.com;
  server_name seconddomain.com;

  location / {
      proxy_pass http://127.0.0.1:8080;
  }

}

but this also don't work

0

It seems that I have found the solution. Yes, you should use nginx as proxy and Apache should listen 8080, for example. The problem in my case was Apache, that listened only external connections, not from 127.0.0.1. So, try to understand first of all if Apache works fine itself, if nginx works fine itself and then try to profixy them. Here is the example of working proxy:

server {
  listen 80 default;

  root /var/www/seconddomain.com;
  server_name seconddomain.com;

  location / {
      proxy_pass http://127.0.0.1:8080;
}

server {
  listen 80;
  server_name firstdomain.com;
  .....
}

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.