3

I'm a Nginx beginner. I rented a little VPS with Ubuntu 12.04 to test. I rented no domain so I make requests directly using the ip. For this question let's assume the ip is 209.208.26.89. Installed the lastest stable Nginx from the official ppa.

After installing Nginx and checking it working ok (going with my browser to http://209.208.26.89) I removed the default configuration from /etc/nginx/sites-enabled. I used this configuration first:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /home/www-data/public-www;
        index index.html index.htm; #index.html is inside /home/www-data/public-www

        server_name 209.208.26.89; #remember, no domain

        location /example {
                root /home/www-data/public-www/example;
                index hello.html; #hello.html is inside /home/www-data/public-www/example
                try_files $uri $uri/ =404;
        }
}

All directories and permissions are correctly set.

When I accessed to http://209.208.26.89/example I was greeted with a 404. The weird thing is that accessing to http://209.208.26.89/ would yield the file hello.html.

How is that suppoused to happen? I'm setting that file to location /example!

However, I tried then with this:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /home/www-data/public-www;
        index index.html index.htm;

        server_name 209.208.26.89; #remember, no domain

        location /example {
                alias /home/www-data/public-www/example; #HERE'S THE CHANGED LINE
                index hello.html;
                try_files $uri $uri/ =404;
        }
}

Using this configuration, http:// 209.208.26.89/example will correctly yield hello.html. BUT http:// 209.208.26.89 will yield the same file.

To make it clear, what I want to do is: when requesting http:// 209.208.26.89/example Nginx should serve me /home/www-data/public-www/example/example.html. I made it with my second configuration, with the drawback of it being server also at http:// 209.208.26.89. But my second requirement is 'http:// 209.208.26.89/' to serve me nothing (should return 404).

I'm sure I'm missing something obvious, but no guide or documentation seems to point me in the right direction. Can anyone help me understand what's happening?

6
  • Why are you setting up a special location? Jan 8, 2014 at 4:26
  • @MichaelHampton I want /home/www-data/public-www/example to be served at /example. That's all :)
    – Fabzter
    Jan 8, 2014 at 4:32
  • You don't need a location for that! Jan 8, 2014 at 4:35
  • Then how can I do it?
    – Fabzter
    Jan 8, 2014 at 4:37
  • You still haven't explained what it is you're trying to do! Jan 8, 2014 at 4:39

1 Answer 1

1

I believe it's caused by this line:

root /home/www-data/public-www;

http://nginx.org/en/docs/http/ngx_http_core_module.html#root

you can remove that, or specify somewhere else.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .