我正在開發一個使用Symfony2,Nginx的項目。Symfony2 Nginx的auth_basic配置不打開網頁資源
項目位於像我的子域名develop_site.mysite.com。
我想在沒有身份驗證的情況下限制對此子域的訪問。不僅要開發和配置文件,還要生產。
所以我添加了auth_basic組件到nginx配置文件中的location/
扇區,在symfony官方網站推薦的nginx配置中。 因此,在頁面加載服務器要求身份驗證並加載除/web
目錄(如圖像,js,css等)中的任何文件存儲以外的所有內容。因此,所有內容都由.php處理,但沒有任何樣式和動態功能。
那麼我該如何解決這個問題?我做錯了什麼?
Nginx的配置是這樣的:
server {
listen {MyServerIp};
server_name developing_site.mysite.com;
root /var/www/developing_site/web;
index index.php index.html index.htm;
location/{
try_files $uri /app.php$is_args$args;
auth_basic "Restricted Content";
auth_basic_user_file var/www/developing_site/.lock/.htpasswd;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
你混合DEV和PROD環境中,你不能在邏輯上具有相同的文件夾2度的環境。嘗試刪除整個#DEV配置塊並重新加載nginx – Miro