Nginx Frontend with Apache2 and Drupal6

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’. I wish to change it so that a visitor only needs
to enter ‘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;

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;
}

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!

I believe all you need is the trailing slash

location /POLL {
proxy_pass 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/;
}

Tried adding the trailing slashes but didn’t work. Caused website url
to change to 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 worked. Anything else?

Thanks for the input.

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, 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 is available for purchase - Sedo.com, it Just Works.

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 ^ mywebsite.com is available for purchase - Sedo.com;

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, 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 is available for purchase - Sedo.com, it Just Works.

The addition above should only affect a request for
http://mywebsite.com/, and should cause the browser to ask for the
working url.

f

Francis D. [email protected]

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’. I wish to change it so that a visitor only needs
to enter ‘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;
}

and it should Just Work.

From your config file, you probably want to use “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. [email protected]

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

Hi there,

However, when I go to mywebsite.com is available for purchase - Sedo.com, thats with 2 trailing slashes, I
get redirected to mywebsite.com is available for purchase - Sedo.com, 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

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

If it is a http redirect to Location: mywebsite.com is available for purchase - Sedo.com
then things are working. Clear your browser cache and try again.

f

Francis D. [email protected]

OK,

I added the following:

location = / {
rewrite ^ mywebsite.com is available for purchase - Sedo.com;
}

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, thats with 2 trailing slashes, I
get redirected to mywebsite.com is available for purchase - Sedo.com, strange but it works! I’m at a
loss as to why. Can you think of how to remedy this?

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. [email protected]
wrote:

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

    f


Francis D. [email protected]


nginx mailing list
[email protected]
nginx Info Page


Cordiali saluti,
Valeriano Cossu

Regards,
Valeriano Cossu

cell: (+39) 3462187419
skype: valerianocossu

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

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. [email protected]