title: Nginx 404 or default page
body: <p>I've developed an Angular 2 app on my mac and have it running locally using Nginx as the websever. I'm having trouble now that I'm deploying this onto an AWS EC2 instance. It's a Linux Red Hat 7 instance.</p>
  
  <p>I've installed Nginx and copied my working config from my mac, making sure to change the server_name value and root, but I either get the default nginx page or 404 errors.</p>
  
  <p>I have setup my app at <code>/var/www/dist</code> and given <code>chmod 755</code> permissions to that path and files in dist. Below is my config (note the angle brackets for server_name aren't in the actual config, I'm just hiding the instance name for this post).</p>
  
  <p>Any attempt at <code>myhost/index.html</code> or <code>myhost/someapppath</code> all return 404. Using <code>myhost/</code> returns the default nginx page. I've even tried checking my root by creating the html dir and putting a file there to test but even that doesn't get picked up. I've restarted nginx after each config too but still get the same. </p>
  
  <p>Any ideas?</p>
  
  <pre><code>user  nginx;
  worker_processes  1;
  
  error_log  /var/log/nginx/error.log warn;
  pid        /var/run/nginx.pid;
  
  
  events {
      worker_connections  1024;
  }
  
  
  http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;
      server_names_hash_bucket_size 128;
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  
      access_log  /var/log/nginx/access.log  main;
  
      sendfile        on;
      #tcp_nopush     on;
  
      keepalive_timeout  65;
  
      #gzip  on;
  
      server {
          listen       80;
          server_name  &lt;hiding instance for this post&gt;.ap-southeast-2.compute.amazonaws.com;
          root /var/www/dist;
          #charset koi8-r;
  
          #access_log  logs/host.access.log  main;
  
          location / {
              index  index.html index.htm;
              try_files $uri $uri$args $uri/index.html /index.html =404;
          }
  
          #error_page  404              /404.html;
  
          # redirect server error pages to the static page /50x.html
          #
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
           root   html;
         }
  
      # proxy the PHP scripts to Apache listening on 127.0.0.1:80
      #
      #location ~ \.php$ {
      #    proxy_pass   http://127.0.0.1;
      #}
  
      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      #location ~ \.php$ {
      #    root           html;
      #    fastcgi_pass   127.0.0.1:9000;
      #    fastcgi_index  index.php;
      #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
      #    include        fastcgi_params;
      #}
  
      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      #location ~ /\.ht {
      #    deny  all;
      #}
  }
  #include /etc/nginx/conf.d/*.conf;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After tinkering with the config again and then looking at the error logs I now see the following:</p>
  
  <p><code>2017/11/16 17:12:14 [crit] 23126#23126: *2 stat() "/var/www/dist/index.html" failed (13: Permission denied)</code></p>
  
  <p>This makes more sense. I've ran <code>sudo chown nginx: var/</code> and <code>sudo chown -R nginx: /var/www</code> for the nginx user and restarted nginx but I still get permission denied. Am I setting the permissions correctly?</p>