Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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;
}

}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
    
Thank you, I'll use include from now on. –  Ivan V. Feb 24 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.