Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Beginner Nginx queries...

  1. #1
    Join Date
    Jan 2010
    Beans
    223
    Distro
    Ubuntu UNR

    Beginner Nginx queries...

    I'm in the midst of trying (failing) to set up a server. I'm using nginx on ubuntu...12.04 (I think, don't quote me, I just downloaded and installed *cough* on a virtual machine).

    Anyway...

    http://arstechnica.com/gadgets/2012/...-web-server/3/

    I got this far and hit a brick wall.

    Code:
    location / {
        try_files $uri $uri/ =404;
    Doesn't actually appear to do anything and I'm not sure why. I changed the server name to check that is what I was actually accessing and it seems to work well *cough*, but this line doesn't seem to matter if I have index.html or not it simply refers back to itself. According to the tutorial it should display a built in 404 error.

    Question: Where'd I screw up?
    Ravenshade

  2. #2
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginner Nginx queries...

    What does the full server block look like?
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  3. #3
    Join Date
    Nov 2008
    Location
    Kingdom of cookies
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Beginner Nginx queries...

    Quote Originally Posted by Ravenshade View Post
    I'm in the midst of trying (failing) to set up a server. I'm using nginx on ubuntu...12.04 (I think, don't quote me, I just downloaded and installed *cough* on a virtual machine).

    Anyway...

    http://arstechnica.com/gadgets/2012/...-web-server/3/

    I got this far and hit a brick wall.

    Code:
    location / {
        try_files $uri $uri/ =404;
    Doesn't actually appear to do anything and I'm not sure why. I changed the server name to check that is what I was actually accessing and it seems to work well *cough*, but this line doesn't seem to matter if I have index.html or not it simply refers back to itself. According to the tutorial it should display a built in 404 error.

    Question: Where'd I screw up?
    It should display a error only if there is no file named $uri or $uri/

    If you access a non-existent file or directory, then the 404 page will show.

    For example, with the configuration below:
    Code:
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to index.html
                    try_files $uri $uri/ =404;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }
            location /normalbehaviour {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to index.html
                    try_files $uri $uri/ /index.html;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }
    Accessing http://199.15.251.155/ will give an index page, because index.html is set as an index and there is a file there called index.html
    Accessing http://199.15.251.155/12345 will give a 404 page because no file/folder exists
    Accessing http://199.15.251.155/normalbehaviour/randomstuff will give an index page, because index.html is set as an index and the site redirects back to the root url.
    Last edited by sandyd; June 1st, 2013 at 11:44 PM.
    Ubuntu Forums Moderation Staff || SandyDNET
    Twitter: @CatchesAStar | Last.fm
    Ubuntu Membership via Forum Contributions

  4. #4
    Join Date
    Jan 2010
    Beans
    223
    Distro
    Ubuntu UNR

    Re: Beginner Nginx queries...

    Gonna have to type all of this out...

    Code:
    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        root /usr/share/nginx/html;
        index index.html index.htm index.php;
    
        server_name hades;
    
        location / {
            try_files $uri $uri/ /index.html =404; #Doesn't matter whether I have /index.html or =404 or both or none. 
        }
    }
    The rest of it is all commented out by default.


    I've typed

    hades/index.html = produces the default nginx page.

    hades/stupidity.me = produces the default nginx page. (there's no such file).

    Remove /index.html replace with =404;

    hades/stupidity.me = still produces the default nginx page.
    Ravenshade

  5. #5
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginner Nginx queries...

    That is what my site does, but the server block is way more complicated.

    Code:
    server {
            listen 80;
            server_name charlesa.net;
            root /webroot/charlesa.net;
            gzip_types application/x-javascript text/css;
            access_log /var/log/nginx/charlesa.net_access.log;
            index index.html index.htm index.php;
    
            location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
                    expires 30d;
                    add_header Pragma public;
                    add_header Cache-Control "public";
            }
    
            location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                    # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
    }
    EDIT: I just noticed I am missing the try statement, but I will have to see what it looks like on the server itself.
    Last edited by CharlesA; June 2nd, 2013 at 12:21 AM.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  6. #6
    Join Date
    Jan 2010
    Beans
    223
    Distro
    Ubuntu UNR

    Re: Beginner Nginx queries...

    S'alright, I'm not entirely sure why mine is not doing as it is supposed to do. I *think* I've followed all the instructions to the letter, I've double checked where I thought I might have slipped up. Though it's not clear which file I should have opened I tested that by changing the server_name variable.

    The only difference from mine and the tutorial is that nginx has inserted a few other things (like listen[::]:80 and I've only included index.php (which apparently doesn't effect the try statement).
    Ravenshade

  7. #7
    Join Date
    Jan 2010
    Beans
    223
    Distro
    Ubuntu UNR

    Re: Beginner Nginx queries...

    My mistake...server_name apparently does nothing.

    Okay...so in site-enabled /etc/nginx/site-enabled/www does nothing apparently. Anyone know a good way to test it. Server_name isn't as reliable as I thought and try_files isn't working at all.
    Last edited by Ravenshade; June 2nd, 2013 at 01:27 AM.
    Ravenshade

  8. #8
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginner Nginx queries...

    What do you have as server_name?

    Works fine for me, but you would need to access the server via that server name - charlesa.net, in my case, not the name of the machine.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  9. #9
    Join Date
    Jan 2010
    Beans
    223
    Distro
    Ubuntu UNR

    Re: Beginner Nginx queries...

    I'm assuming I set the server name in server block right?

    In which case, I've tried hades, which works, I've changed the name to luna...which doesn't work ._.;

    ifconfig doesn't 'appear' to have a hostname anywhere...and I know I called it hades somewhere.... (by the way, this is only intended to be localhosted at the moment 192.168.1.83 is the local ip address).

    basically, if I type "Hades" into the address bar of my host machine, it heads off to the server (as expected).

    If I change server_name to 'Luna' then type luna into the address bar of the host machine... it googles luna instead! *shakes fist*. So doesn't work with any other setting and the try statement doesn't work either. >.>

    okay, found hostname (shoots self). Reset server_name to hades...but apparently makes no difference.
    Last edited by Ravenshade; June 2nd, 2013 at 02:10 AM.
    Ravenshade

  10. #10
    Join Date
    Jan 2010
    Beans
    223
    Distro
    Ubuntu UNR

    Re: Beginner Nginx queries...

    O_o... okay...something works now. (not sure wtf I did though).

    Though I had a reaction from /etc/init.d/nginx reload that I hadn't had before. Eg, it actually came up with something before moving on. Which probably means, unless you're 'root' you're not allowed to change things which means I screwed up -_-; (too used to doing things user side not admin side that I now feel uncomfortable staying in root XD)

    I'll mark thread as solved.

    Solution: You need to be root it seems.
    Ravenshade

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •