snumb130

NGINX try_files and alias bug work around

Jan 27th, 2015
5,284
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 2.18 KB | None | 0 0
  1. server {                                                                                                                                                                                                                                  
  2.     listen 80; ## Listen on port 80 ##
  3.     server_name example.com;  ## Domain Name ##
  4.     root /home/vagrant/example.com/angular/build;  ## Site root for the Angular code ##
  5.  
  6.     index index.html index.php;  ## Set the index for site to use ##
  7.  
  8.     charset utf-8; ## Set the charset ##
  9.  
  10.     location / { ## Handle default requests ##
  11.         try_files $uri $uri/ /index.html;  ## Try files and fall back to index.html ##
  12.     }
  13.  
  14.     location /api { ## URL string to use for api ##
  15.         alias /home/vagrant/example.com/laravel/public; ## Site root for Laravel code ##
  16.  
  17.         ## Check for file existing and if there, stop ##
  18.         if (-f $request_filename) {
  19.             break;
  20.         }
  21.  
  22.         ## Check for file existing and if there, stop ##
  23.         if (-d $request_filename) {
  24.             break;
  25.         }
  26.  
  27.         ## If we get here then there is no file or directory matching request_filename ##
  28.         rewrite (.*) /api/index.php?$query_string;
  29.  
  30.         ## Normal php block for processing ##
  31.         location ~ \.php$ {
  32.             fastcgi_split_path_info ^(.+\.php)(/.+)$;
  33.             fastcgi_pass unix:/var/run/php5-fpm.sock;
  34.             fastcgi_index index.php;
  35.             include fastcgi_params;
  36.         }
  37.     }
  38.  
  39.     ## Don't fail or log request to favicon or robots.txt ##
  40.     location = /favicon.ico { access_log off; log_not_found off; }
  41.     location = /robots.txt  { access_log off; log_not_found off; }
  42.  
  43.     ## Access log is off and error log location is set ##
  44.     access_log off;
  45.     error_log  /var/log/nginx/example.com-error.log error;
  46.  
  47.     ## Disable sendfile ##
  48.     sendfile off;
  49.  
  50.     ## Normal php block for processing ##
  51.     location ~ \.php$ {
  52.         fastcgi_split_path_info ^(.+\.php)(/.+)$;
  53.         fastcgi_pass unix:/var/run/php5-fpm.sock;
  54.         fastcgi_index index.php;
  55.         include fastcgi_params;
  56.     }
  57.  
  58.     ## Don't allow access to .ht files ##
  59.     location ~ /\.ht {
  60.         deny all;
  61.     }
  62. }
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment