# Nginx Frontend with Apache2 and Drupal6

**URL:** <https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744>\
**Category:** NGINX\
**Created:** [September 8, 2012, 8:16pm UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744 "2012-09-08T20:16:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 8, 2012, 8:16pm UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/1 "2012-09-08T20:16:44Z")

</div>

Hi,

I have a dedicated server running Nginx as a front end and apache2 on  
port:8080. An online game is installed as an application in drupal6.  
The site works fine without any issues. The problem is that when  
someone wants to visit the site; it is necessary to enter  
‘[example.com/drupal6](http://example.com/drupal6)’. I wish to change it so that a visitor only needs  
to enter ‘[example.com](http://example.com)’ to access the drupal site. I have tried many  
modifications of the Nginx and apache2 configuration files without  
success. I usually end up breaking something. I would appreciate if  
some could offer some advice in this area.

here is how my server is configured.

_ **NGINX 0.7.67** _

**sites-available/default**

server {  
listen 80;  
server\_name [mywebsit.com](http://mywebsit.com);

access\_log /var/log/nginx/localhost.access.log;

```
   location /POLL {
            proxy_pass http://127.0.0.1:8081;
    }

   location /RADIOEDIT_REST {
            proxy_pass http://127.0.0.1:19384/RADIOEDIT_REST;
    }

```

location / {  
proxy\_pass [http://127.0.0.1:8080](http://127.0.0.1:8080);  
}

location /doc {  
root /usr/share;  
autoindex on;  
allow 127.0.0.1;  
deny all;  
}

location /images {  
root /usr/share;  
autoindex on;  
}

error\_page 500 502 503 504 /50x.html;  
location = /50x.html {  
root /var/www/nginx-default;  
}  
}

**nginx/nginx.conf**

user www-data;  
worker\_processes 4;

error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

```

}

\*_ **nginx/conf.d/proxy.conf** _

proxy\_redirect off;  
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\_buffering off;  
proxy\_read\_timeout 300;  
proxy\_buffers 64 8k;  
proxy\_buffer\_size 128k;

_ **APACHE2** _

**apache2/sites-available/default**

proxy\_redirect off;  
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\_buffering off;  
proxy\_read\_timeout 300;  
proxy\_buffers 64 8k;  
proxy\_buffer\_size 128k;

**apache2/ports.conf**

# If you just change the port or add more ports here, you will likely

also

# have to change the VirtualHost statement in

# /etc/apache2/sites-enabled/000-default

# This is also true if you have upgraded from before 2.2.9-3 (i.e. from

# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and

# README.Debian.gz

NameVirtualHost \*:8080  
Listen 8080

 # If you add NameVirtualHost \*:443 here, you will also have to change # the VirtualHost statement in /etc/apache2/sites-available/default-ssl # to # Server Name Indication for SSL named virtual hosts is currently not # supported by MSIE on Windows XP. Listen 443 Listen 443

**apache2/conf.d/drupal6**

Alias /drupal6 /usr/share/drupal6

\<Directory /usr/share/drupal6/\>  
Options +FollowSymLinks  
AllowOverride All  
order allow,deny  
allow from all

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 8, 2012, 8:29pm UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/2 "2012-09-08T20:29:15Z")

</div>

I believe all you need is the trailing slash

location /POLL {  
proxy\_pass [http://127.0.0.1:8081/](http://127.0.0.1:8081/);  
}

```
  location /RADIOEDIT_REST {
           proxy_passhttp://127.0.0.1:19384/RADIOEDIT_REST/;
   }

```

location / {  
proxy\_pass [http://127.0.0.1:8080/](http://127.0.0.1:8080/);  
}

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 8, 2012, 11:32pm UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/3 "2012-09-08T23:32:15Z")

</div>

Tried adding the trailing slashes but didn’t work. Caused website url  
to change to [mywebsite.com:8080/drupal6](http://mywebsite.com:8080/drupal6) content was visible but game  
application didn’t work. Also broke the original link whereas  
[mywebsite.com is available for purchase - Sedo.com](http://mywebsite.com/drupal6) worked. Anything else?

Thanks for the input.

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 1:34am UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/4 "2012-09-09T01:34:13Z")

</div>

Thanks Francis,

I tried your suggestion but I get this error after restarting nginx:  
Restarting nginx: [emerg]: invalid number of arguments in “return”  
directive in /etc/nginx/sites-enabled/default:22.

For clarification, the default behavior has been when a user goes to  
[mywebsite.com](http://mywebsite.com), the address bar in the browser shows  
[mywebsite.com:8080/drupal6/](http://mywebsite.com:8080/drupal6/), the content shows but the game doesn’t  
work. If a user goes to [mywebsite.com is available for purchase - Sedo.com](http://mywebsite.com/drupal6/), it Just Works.

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 1:45am UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/5 "2012-09-09T01:45:16Z")

</div>

On Sun, Sep 09, 2012 at 01:34:13AM +0200, Larry P. wrote:

Hi there,

> I tried your suggestion but I get this error after restarting nginx:  
> Restarting nginx: [emerg]: invalid number of arguments in “return”  
> directive in /etc/nginx/sites-enabled/default:22.

Ah, my mistake. The nginx version you use doesn’t have the same “return”  
directive syntax.

rewrite ^ [http://mywebsite.com/drupal6/](http://mywebsite.com/drupal6/);

instead of the “return” line should probably work. (It still goes inside  
the “location = /” block.)

> For clarification, the default behavior has been when a user goes to  
> [mywebsite.com](http://mywebsite.com), the address bar in the browser shows  
> mywebsite.com:8080/drupal6/, the content shows but the game doesn’t  
> work. If a user goes to [mywebsite.com/drupal6/](http://mywebsite.com/drupal6/), it Just Works.

The addition above should _only_ affect a request for  
[http://mywebsite.com/](http://mywebsite.com/), and should cause the browser to ask for the  
working url.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 12:41am UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/6 "2012-09-09T00:41:35Z")

</div>

On Sat, Sep 08, 2012 at 08:16:44PM +0200, Larry P. wrote:

Hi there,

> The site works fine without any issues. The problem is that when  
> someone wants to visit the site; it is necessary to enter  
> ‘[example.com/drupal6](http://example.com/drupal6)’. I wish to change it so that a visitor only needs  
> to enter ‘[example.com](http://example.com)’ to access the drupal site.

So, leave everything as-is, except if the user goes to the root of the  
site, they end up at the drupal url?

Add

location = / {  
return 301 [http://example.com/drupal6](http://example.com/drupal6);  
}

and it should Just Work.

From your config file, you probably want to use “[mywebsit.com](http://mywebsit.com)” up there;  
and if the first thing a request to /drupal6 does is redirect you to  
/drupal6/, then you should probably use that instead too.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 11:18am UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/7 "2012-09-09T11:18:51Z")

</div>

On Sun, Sep 09, 2012 at 02:34:43AM +0200, Larry P. wrote:

Hi there,

> However, when I go to [mywebsite.com//](http://mywebsite.com//), thats with 2 trailing slashes, I  
> get redirected to [mywebsite.com/drupal6/](http://mywebsite.com/drupal6/), strange but it works! I’m at a  
> loss as to why. Can you think of how to remedy this?

“Two slashes” works because (probably) nginx merges them into one.

“One slash” probably doesn’t seem to work because of browser caching,  
I guess.

What is the output of

curl -i [http://mywebsite.com](http://mywebsite.com)

(which I presume is the request you want to have work)?

If it is a http redirect to Location: [http://mywebsite.com/drupal6/](http://mywebsite.com/drupal6/)  
then things are working. Clear your browser cache and try again.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 2:34am UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/8 "2012-09-09T02:34:43Z")

</div>

OK,

I added the following:

location = / {  
rewrite ^ [mywebsite.com is available for purchase - Sedo.com](http://mywebsite.com/drupal6/);  
}

and at first it seemed as if nothing had changed from the default  
behavior.  
However, when I go to [mywebsite.com is available for purchase - Sedo.com](http://mywebsite.com//), thats with 2 trailing slashes, I  
get redirected to [mywebsite.com is available for purchase - Sedo.com](http://mywebsite.com/drupal6/), strange but it works! I’m at a  
loss as to why. Can you think of how to remedy this?

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 3:17pm UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/9 "2012-09-09T15:17:10Z")

</div>

Hi there,

2 slashes are different than 1 slash in nginx, there is a config param  
for  
that somewhre to set for that, read the doc to find that on the wiki

saluti

On Sun, Sep 9, 2012 at 11:18 AM, Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> “One slash” probably doesn’t seem to work because of browser caching,
> 
> ```
> f
> 
> ```
> 
> –  
> Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Cordiali saluti,  
Valeriano Cossu

Regards,  
Valeriano Cossu

cell: (+39) 3462187419  
skype: valerianocossu

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 2:59pm UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/10 "2012-09-09T14:59:47Z")

</div>

Hi Francis,

Curl -i showed the correct url and clearing the cache solved the  
problem! Thank you for lending me your expert and methodical advice.  
Your assistance has also helped me understand more how NGINX works.  
Dealing with it in the future will be that much easier!

Larry

---

<div class="post-metadata">

**Author:** ![larry\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@larry\_p](https://www.ruby-forum.com/u/larry_p)\
**Post date:** [September 9, 2012, 3:55pm UTC](https://www.ruby-forum.com/t/nginx-frontend-with-apache2-and-drupal6/222744/11 "2012-09-09T15:55:43Z")

</div>

On Sun, Sep 09, 2012 at 02:59:47PM +0200, Larry P. wrote:

Hi there,

> Curl -i showed the correct url and clearing the cache solved the  
> problem! Thank you for lending me your expert and methodical advice.  
> Your assistance has also helped me understand more how NGINX works.  
> Dealing with it in the future will be that much easier!

You’re welcome; and good that you’ve found a working solution.

One side issue, which might be worth investigating more fully later, is  
that the fact that port 8080 sometimes “leaks” to the client indicates  
that there is still something wrong with some part of the configuration  
– nginx on port 80 is the initial entry point, but it is not a pure  
“frontend” if the client is directly accessing apache.

If if matters, you may want to check which requests lead to the client  
seeing a link to, or a redirect to, port 8080.

If it doesn’t matter, then there’s nothing to worry about.

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
