第一次使用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; } }
这是include的。 我可以看到你已经使用过两次了!