Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx single application config

I'm writing an AngularJS single page application using nginx.

I just switched from apache to nginx, but I cant make my config file working. I'm trying to rewrite everything to index.html to let Angular do the routing.

My nginx.conf is as follow:

server {
  index index.html;

  location / {
    expires -1;
    add_header Pragma "no-cache";
    add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    try_files $uri $uri/ /index.html;
  }
}

Is it possible to have my nginx.conf file in the project root like my .htaccess did?

like image 413
guidsen Avatar asked Jul 23 '14 19:07

guidsen


1 Answers

You dont want nginx.conf in the project root and its not necessary. Also, you don't want direct changes to nginx.conf, you will instead want specific files for different websites in /etc/nginx/sites-available which you enable with a ln in /etc/nginx/sites-enabled.

As far as the config:

server {
 root /var/www/mysite/; #or whereever your site files are
 index index.html;

 location /{
  try_files $uri $uri/ =404;
 }
}

You are missing the root portion which tells nginx where the site is located.

like image 50
Fourth Avatar answered Nov 15 '22 02:11

Fourth