1

First time working with nginx. Due to my limited knowledge of location directive precedence I had to repeat the code at two places (fastcgi). Can I optimize this file and not repeat code?

This is my server file.

server{
  server_name www.theme-dev.local;
  return 301 $scheme://theme-dev.local$request_uri;
}

server {
listen 80;

root /var/www;

error_log /var/log/nginx/theme-dev.local/server.log warn;

index index.php index.html;

server_name theme-dev.local;

chunked_transfer_encoding off;
proxy_buffering off;

location = /robots.txt {
    access_log off;
    log_not_found off;
}

location = /favicon.ico {
    access_log off;
    log_not_found off;
}


location ~ /\.ht {
    access_log off;
    deny all;
 }


location ~* /themes/subfolder/wordpress_home/(wp-admin|wp-login.php)$ {
    auth_basic "WordPress Login";
    auth_basic_user_file /etc/nginx/my_auth/.htpasswd;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    include fastcgi_params;

}

location /themes/subfolder/wordpress_home/ {
    try_files $uri $uri/ /themes/subfolder/wordpress_home/index.php?q=$uri&$args;
}

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    include fastcgi_params;
}

}

1 Answer 1

0

That is what include is for. I can see that you've already used it twice!

1
  • Thank you, I'll use include from now on.
    – Ivan V.
    Feb 24, 2014 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .