Nginx Apache Reverse Proxy Redirects to the Wrong Directory











up vote
0
down vote

favorite












I followed this guide to set up Nginx with reverse proxy for Apache.
I'm having trouble getting my domain name to redirect to correct page. I have several subdomains as well, and some of them redirect correctly, and others do not.
I have the following file structure where I place my website files:



/var/www/
html
index.php
mysite.com
public_html
index.php
sub1
public_html
index.php
sub2
public_html
index.html


NOTE: I have more than two subdomains, but I have only listed two here for simplicity's sake. You can assume that the others follow the same basic structure as one or the other of the subdomains listed here. There are more files than just index.php/index.html in each directory.



I seems like the server blocks that work are the ones that have index.html, and the ones that don't work have index.php.



When I say they "don't work", I mean that it redirects to /var/www/html/index.php instead of the correct index.php file in the server's corresponding directory.



For example, if I go to mysite.com, instead of taking me to /var/www/mysite.com/public_html/index.php, it takes me to var/www/html/index.php.



Likewise, when I visit sub1.mysite.com, I am taken to var/www/html/index.php.



When I visit sub2.mysite.com, I am taken to var/www/sub2/public_html/index.html.



I think this has something to do with config in step 11, where PHP files are redirected to Apache, but I can't figure out how to redirect them to the correct directory.



Here are my config files (with PII subbed out):



/etc/nginx/sites-available/apache



server {
listen 80;
server_name mysite.com www.mysite.com;
root /var/www/mysite.com/public_html;
index index.php index.htm index.html;

location / {
try_files $uri $uri/ /index.php;
}

location ~ .php$ {
proxy_pass http://<server-ip>:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ /.ht {
deny all;
}
}

server {
listen 80;
server_name sub1.mysite.com www.sub1.mysite.com;
root /var/www/sub1/public_html;
index index.php index.htm index.html;

location / {
try_files $uri $uri/ /index.php;
}

location ~ .php$ {
proxy_pass http://<server-ip>:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ /.ht {
deny all;
}
}

server {
listen 80;
server_name sub2.mysite.com www.sub2.mysite.com;
root /var/www/sub2/public_html;
index index.php index.htm index.html;

location / {
try_files $uri $uri/ /index.php;
}

location ~ .php$ {
proxy_pass http://<server-ip>:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ /.ht {
deny all;
}
}


/etc/apache2/sites-available/mysite.com.conf



<VirtualHost *:8080>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/public_html
<Directory /var/www/mysite.com/public_html>
AllowOverride All
</Directory>
</VirtualHost>


/etc/apache2/sites-available/sub1.conf



<VirtualHost *:8080>
ServerName sub1.mysite.com
ServerAlias www.sub1.mysite.com
DocumentRoot /var/www/sub1/public_html
<Directory /var/www/sub1/public_html>
AllowOverride All
</Directory>
</VirtualHost>


/etc/apache2/sites-available/sub2.conf



<VirtualHost *:8080>
ServerName sub2.mysite.com
ServerAlias www.sub2.mysite.com
DocumentRoot /var/www/sub2/public_html
<Directory /var/www/sub2/public_html>
AllowOverride All
</Directory>
</VirtualHost>


I have created the symlink between /etc/apache2/sites-available/ and /etc/apache2/sites-enabled/ as well as between between /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ as described in the guide.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I followed this guide to set up Nginx with reverse proxy for Apache.
    I'm having trouble getting my domain name to redirect to correct page. I have several subdomains as well, and some of them redirect correctly, and others do not.
    I have the following file structure where I place my website files:



    /var/www/
    html
    index.php
    mysite.com
    public_html
    index.php
    sub1
    public_html
    index.php
    sub2
    public_html
    index.html


    NOTE: I have more than two subdomains, but I have only listed two here for simplicity's sake. You can assume that the others follow the same basic structure as one or the other of the subdomains listed here. There are more files than just index.php/index.html in each directory.



    I seems like the server blocks that work are the ones that have index.html, and the ones that don't work have index.php.



    When I say they "don't work", I mean that it redirects to /var/www/html/index.php instead of the correct index.php file in the server's corresponding directory.



    For example, if I go to mysite.com, instead of taking me to /var/www/mysite.com/public_html/index.php, it takes me to var/www/html/index.php.



    Likewise, when I visit sub1.mysite.com, I am taken to var/www/html/index.php.



    When I visit sub2.mysite.com, I am taken to var/www/sub2/public_html/index.html.



    I think this has something to do with config in step 11, where PHP files are redirected to Apache, but I can't figure out how to redirect them to the correct directory.



    Here are my config files (with PII subbed out):



    /etc/nginx/sites-available/apache



    server {
    listen 80;
    server_name mysite.com www.mysite.com;
    root /var/www/mysite.com/public_html;
    index index.php index.htm index.html;

    location / {
    try_files $uri $uri/ /index.php;
    }

    location ~ .php$ {
    proxy_pass http://<server-ip>:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /.ht {
    deny all;
    }
    }

    server {
    listen 80;
    server_name sub1.mysite.com www.sub1.mysite.com;
    root /var/www/sub1/public_html;
    index index.php index.htm index.html;

    location / {
    try_files $uri $uri/ /index.php;
    }

    location ~ .php$ {
    proxy_pass http://<server-ip>:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /.ht {
    deny all;
    }
    }

    server {
    listen 80;
    server_name sub2.mysite.com www.sub2.mysite.com;
    root /var/www/sub2/public_html;
    index index.php index.htm index.html;

    location / {
    try_files $uri $uri/ /index.php;
    }

    location ~ .php$ {
    proxy_pass http://<server-ip>:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /.ht {
    deny all;
    }
    }


    /etc/apache2/sites-available/mysite.com.conf



    <VirtualHost *:8080>
    ServerName mysite.com
    ServerAlias www.mysite.com
    DocumentRoot /var/www/mysite.com/public_html
    <Directory /var/www/mysite.com/public_html>
    AllowOverride All
    </Directory>
    </VirtualHost>


    /etc/apache2/sites-available/sub1.conf



    <VirtualHost *:8080>
    ServerName sub1.mysite.com
    ServerAlias www.sub1.mysite.com
    DocumentRoot /var/www/sub1/public_html
    <Directory /var/www/sub1/public_html>
    AllowOverride All
    </Directory>
    </VirtualHost>


    /etc/apache2/sites-available/sub2.conf



    <VirtualHost *:8080>
    ServerName sub2.mysite.com
    ServerAlias www.sub2.mysite.com
    DocumentRoot /var/www/sub2/public_html
    <Directory /var/www/sub2/public_html>
    AllowOverride All
    </Directory>
    </VirtualHost>


    I have created the symlink between /etc/apache2/sites-available/ and /etc/apache2/sites-enabled/ as well as between between /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ as described in the guide.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I followed this guide to set up Nginx with reverse proxy for Apache.
      I'm having trouble getting my domain name to redirect to correct page. I have several subdomains as well, and some of them redirect correctly, and others do not.
      I have the following file structure where I place my website files:



      /var/www/
      html
      index.php
      mysite.com
      public_html
      index.php
      sub1
      public_html
      index.php
      sub2
      public_html
      index.html


      NOTE: I have more than two subdomains, but I have only listed two here for simplicity's sake. You can assume that the others follow the same basic structure as one or the other of the subdomains listed here. There are more files than just index.php/index.html in each directory.



      I seems like the server blocks that work are the ones that have index.html, and the ones that don't work have index.php.



      When I say they "don't work", I mean that it redirects to /var/www/html/index.php instead of the correct index.php file in the server's corresponding directory.



      For example, if I go to mysite.com, instead of taking me to /var/www/mysite.com/public_html/index.php, it takes me to var/www/html/index.php.



      Likewise, when I visit sub1.mysite.com, I am taken to var/www/html/index.php.



      When I visit sub2.mysite.com, I am taken to var/www/sub2/public_html/index.html.



      I think this has something to do with config in step 11, where PHP files are redirected to Apache, but I can't figure out how to redirect them to the correct directory.



      Here are my config files (with PII subbed out):



      /etc/nginx/sites-available/apache



      server {
      listen 80;
      server_name mysite.com www.mysite.com;
      root /var/www/mysite.com/public_html;
      index index.php index.htm index.html;

      location / {
      try_files $uri $uri/ /index.php;
      }

      location ~ .php$ {
      proxy_pass http://<server-ip>:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }

      location ~ /.ht {
      deny all;
      }
      }

      server {
      listen 80;
      server_name sub1.mysite.com www.sub1.mysite.com;
      root /var/www/sub1/public_html;
      index index.php index.htm index.html;

      location / {
      try_files $uri $uri/ /index.php;
      }

      location ~ .php$ {
      proxy_pass http://<server-ip>:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }

      location ~ /.ht {
      deny all;
      }
      }

      server {
      listen 80;
      server_name sub2.mysite.com www.sub2.mysite.com;
      root /var/www/sub2/public_html;
      index index.php index.htm index.html;

      location / {
      try_files $uri $uri/ /index.php;
      }

      location ~ .php$ {
      proxy_pass http://<server-ip>:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }

      location ~ /.ht {
      deny all;
      }
      }


      /etc/apache2/sites-available/mysite.com.conf



      <VirtualHost *:8080>
      ServerName mysite.com
      ServerAlias www.mysite.com
      DocumentRoot /var/www/mysite.com/public_html
      <Directory /var/www/mysite.com/public_html>
      AllowOverride All
      </Directory>
      </VirtualHost>


      /etc/apache2/sites-available/sub1.conf



      <VirtualHost *:8080>
      ServerName sub1.mysite.com
      ServerAlias www.sub1.mysite.com
      DocumentRoot /var/www/sub1/public_html
      <Directory /var/www/sub1/public_html>
      AllowOverride All
      </Directory>
      </VirtualHost>


      /etc/apache2/sites-available/sub2.conf



      <VirtualHost *:8080>
      ServerName sub2.mysite.com
      ServerAlias www.sub2.mysite.com
      DocumentRoot /var/www/sub2/public_html
      <Directory /var/www/sub2/public_html>
      AllowOverride All
      </Directory>
      </VirtualHost>


      I have created the symlink between /etc/apache2/sites-available/ and /etc/apache2/sites-enabled/ as well as between between /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ as described in the guide.










      share|improve this question













      I followed this guide to set up Nginx with reverse proxy for Apache.
      I'm having trouble getting my domain name to redirect to correct page. I have several subdomains as well, and some of them redirect correctly, and others do not.
      I have the following file structure where I place my website files:



      /var/www/
      html
      index.php
      mysite.com
      public_html
      index.php
      sub1
      public_html
      index.php
      sub2
      public_html
      index.html


      NOTE: I have more than two subdomains, but I have only listed two here for simplicity's sake. You can assume that the others follow the same basic structure as one or the other of the subdomains listed here. There are more files than just index.php/index.html in each directory.



      I seems like the server blocks that work are the ones that have index.html, and the ones that don't work have index.php.



      When I say they "don't work", I mean that it redirects to /var/www/html/index.php instead of the correct index.php file in the server's corresponding directory.



      For example, if I go to mysite.com, instead of taking me to /var/www/mysite.com/public_html/index.php, it takes me to var/www/html/index.php.



      Likewise, when I visit sub1.mysite.com, I am taken to var/www/html/index.php.



      When I visit sub2.mysite.com, I am taken to var/www/sub2/public_html/index.html.



      I think this has something to do with config in step 11, where PHP files are redirected to Apache, but I can't figure out how to redirect them to the correct directory.



      Here are my config files (with PII subbed out):



      /etc/nginx/sites-available/apache



      server {
      listen 80;
      server_name mysite.com www.mysite.com;
      root /var/www/mysite.com/public_html;
      index index.php index.htm index.html;

      location / {
      try_files $uri $uri/ /index.php;
      }

      location ~ .php$ {
      proxy_pass http://<server-ip>:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }

      location ~ /.ht {
      deny all;
      }
      }

      server {
      listen 80;
      server_name sub1.mysite.com www.sub1.mysite.com;
      root /var/www/sub1/public_html;
      index index.php index.htm index.html;

      location / {
      try_files $uri $uri/ /index.php;
      }

      location ~ .php$ {
      proxy_pass http://<server-ip>:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }

      location ~ /.ht {
      deny all;
      }
      }

      server {
      listen 80;
      server_name sub2.mysite.com www.sub2.mysite.com;
      root /var/www/sub2/public_html;
      index index.php index.htm index.html;

      location / {
      try_files $uri $uri/ /index.php;
      }

      location ~ .php$ {
      proxy_pass http://<server-ip>:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }

      location ~ /.ht {
      deny all;
      }
      }


      /etc/apache2/sites-available/mysite.com.conf



      <VirtualHost *:8080>
      ServerName mysite.com
      ServerAlias www.mysite.com
      DocumentRoot /var/www/mysite.com/public_html
      <Directory /var/www/mysite.com/public_html>
      AllowOverride All
      </Directory>
      </VirtualHost>


      /etc/apache2/sites-available/sub1.conf



      <VirtualHost *:8080>
      ServerName sub1.mysite.com
      ServerAlias www.sub1.mysite.com
      DocumentRoot /var/www/sub1/public_html
      <Directory /var/www/sub1/public_html>
      AllowOverride All
      </Directory>
      </VirtualHost>


      /etc/apache2/sites-available/sub2.conf



      <VirtualHost *:8080>
      ServerName sub2.mysite.com
      ServerAlias www.sub2.mysite.com
      DocumentRoot /var/www/sub2/public_html
      <Directory /var/www/sub2/public_html>
      AllowOverride All
      </Directory>
      </VirtualHost>


      I have created the symlink between /etc/apache2/sites-available/ and /etc/apache2/sites-enabled/ as well as between between /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ as described in the guide.







      ubuntu apache-http-server nginx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 23:13









      MattR

      64




      64



























          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377127%2fnginx-apache-reverse-proxy-redirects-to-the-wrong-directory%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377127%2fnginx-apache-reverse-proxy-redirects-to-the-wrong-directory%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          AnyDesk - Fatal Program Failure

          How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

          QoS: MAC-Priority for clients behind a repeater