优化 nginx 站点配置

优化 nginx 站点配置

第一次使用 nginx。由于我对location指令优先级的了解有限,我不得不在两个地方重复代码(fastcgi)。我可以优化这个文件而不重复代码吗?

这是我的服务器文件。

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

这就是include是。我看你已经用过两次了!

相关内容