0

I'm setting up a server on Rackspace for migrating an existing website to so I can have everything working before changing the DNS entry.

I had no problems getting the server to work at the IP address using the default setup. I then copied the original sites-available file, symlinked to it in sites-enabled, and copied the original index.html to a new folder. I set the sites-available root to the new folder and did chown -R www-data:www-data, chmod 775 on the folder, and chmod 664 on the file. After which I restarted Nginx.

When I bring up the IP address of the site, I get 404 Not Found.

Here is sites-available:

server {
    listen [::]:80 default_server;
    root /var/www/example.com/public/;
    index index.html index.htm;        
    server_name localhost;
    location / {
            try_files $uri $uri/ =404;
       }
}
Paul
  • 3,037
  • 6
  • 27
  • 40
  • Do you have other sites operating on this setup? and how are you accessing the site? `http://localhost`? or IP? – Simon Hayter Apr 21 '13 at 17:11
  • I am accessing the site through its public IP address. Yes, I have quite a few sites across several LEMP servers with Rackspace. – Paul Apr 21 '13 at 17:37
  • Well in your config you have server_name localhost, have you tried the IP address and without the default_server. – Simon Hayter Apr 21 '13 at 17:51
  • I believe this problem is because your not using a FQDN and the configuration is not assigning the virtual host to the site. Try server_name ip. Alternatively you can always get a free domain purely for testing purposes. Look online for free domain, there is plenty.. for example http://www.freedomain.co.nr/ – Simon Hayter Apr 21 '13 at 17:52
  • I just tried those things and they didn't work. Maybe I should have stated the question more simpler: Why does nginx work at the server IP address with /usr/share/nginx/html as root and not /var/www/example.com/public? – Paul Apr 21 '13 at 19:24
  • Dunno you might be better asking to migrate the question to server fault if you think. – Simon Hayter Apr 21 '13 at 19:43

2 Answers2

1

Ever the humbling experience, Linux is. Someone on the nginx mailing list kindly pointed out that I should check permissions of /var/www/, and low and behold, I had accidentally entered the wrong code when I did chmod on /var/www/. Everything works properly now. On with the migration...

Paul
  • 3,037
  • 6
  • 27
  • 40
0

The problem I see straight away is that you have a tailing slash on the root option.

Change /var/www/example.com/public/

Change to: /var/www/example.com/public

Additionally if you don't have any luck with the above try the below code, this gets rid of the localhost element and hard sets the domain that you want to use.

server {
    listen       80;
    server_name  your-domain.com www.yourdomain.com;
    root /var/www/example.com/public;
    index index.html index.htm;        
    location / { }
    error_page   404      /404x.html;
}
Simon Hayter
  • 329
  • 2
  • 11
  • The trailing slash is included in default root location, so changing that didn't make any difference. Setting the server_name made no difference either. I have actually encountered the problem before and got around it with a spare domain, but I don't have a spare domain to use right now. There is something peculiar about serving with an IP address. I can change nothing but the root location and then the site will work at the IP address. – Paul Apr 21 '13 at 17:02