Katai
Katai

Reputation: 2937

Other solutions, instead of .htaccess for NGINX

I'm working on a larger Web based Project, that probably will have to handle a couple of hundred requests per minute in a later stage (or more).

I never worked with NGINX, but reading the comparisions with apache, it seems that I probably should go the NGINX route. Reading about it, I always see that '.htaccess' files are a lazy solution. Now, I would like to avoid relying on .htaccess files, but my question is how?

What I mean is - if .htaccess are considered the lazy, hacky solution, what exactly is the clean solution for this issues:

This are basically the three things I'm using .htaccess for. Especially the first one, basically makes the whole Application work at all.

But for this Project, I'm really trying to stay clean, and up-to-date, solution wise. What are my possibilities? Where could I increase my performance? And how can I solve the 3 mentioned problems, whitout using a .htaccess, to develop on NGINX?

Thank you very much for your time and effort.

Upvotes: 3

Views: 1372

Answers (2)

Burhan Khalid
Burhan Khalid

Reputation: 174690

In order to get the most out of nginx, you have to understand that it is not a web server (like Apache), but a proxy. In simple terms, it acts like a giant rule engine to pass stuff along to other applications based on pattern matching on requests.

So to run PHP with nginx, you need a separate server (or process) that runs PHP. This can be Apache, but PHP includes a FastCGI Process Manager (FPM).

Here is basic boilerplate to get you going:

server {
   listen 80;
   server_name www.example.com example.com;
   access_log /var/www/www.example.com/logs/access.log;
   error_log /var/www/www.example.com/logs/error.log;
   root /var/www/www.example.com/public_html;

   location / {
       index  index.html index.htm index.php;
       auth_basic            "Username Required";
       auth_basic_user_file  /etc/nginx/htpasswd;
   }

   location ~ (\.php|\.css)$ {
       try_files $uri =404;

       include /etc/nginx/fastcgi_params;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_pass php;
   } 
}

Upvotes: 4

Related Questions