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.
ubuntu apache-http-server nginx
add a comment |
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.
ubuntu apache-http-server nginx
add a comment |
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.
ubuntu apache-http-server nginx
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
ubuntu apache-http-server nginx
asked Nov 20 at 23:13
MattR
64
64
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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