2017-08-29 53 views
0

我們正試圖在Nandx上設置我們的Zandbox /測試站點上的Klaviyo。Nginx auth off整個文件夾

但是,當我啓用htpasswd時,Klaviyo無法從SOAP獲取數據。 它需要訪問www.mytestdomain.com/api/v2_soap?wsdl=1才能獲取數據。

如何禁用整個api文件夾的auth_basic?我已經做了一些PHP文件,但因爲這不是一個特定的PHP文件,我不知道。我使用的PHP文件中的代碼是:

location = /folder/file.php { 
    auth_basic off; 
    try_files $uri =404; 
    expires off; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    proxy_connect_timeout 2600s; 
    proxy_send_timeout 2600s; 
    proxy_read_timeout 2600s; 
    fastcgi_send_timeout 2600s; 
    fastcgi_read_timeout 2600s; 
    fastcgi_pass zandbox; 
    fastcgi_pass_request_headers on; 
    fastcgi_keep_conn off; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root${fastcgi_script_name}; 
    fastcgi_param MAGE_RUN_CODE base; 
    fastcgi_param MAGE_RUN_TYPE website; 
    } 

的完整代碼:

server { 
    listen 80; 
    server_name mydomain.dk www.mydomain.dk; 
    return 301 https://www.mydomain.dk$request_uri; 
} 

server { 
    listen 443 ssl; 
    server_name mydomain.dk; 

    ssl on; 
    ssl_certificate /etc/ssl/www_mydomain_dk.crt; 
    ssl_certificate_key /etc/ssl/www_mydomain_dk.key; 
    include /etc/nginx/ssl_common.conf; 

    return 301 https://www.mydomain.dk$request_uri; 

} 

server { 
    listen 443 ssl; 
    server_name www.mydomain.dk; 

    auth_basic "Restricted"; 
    auth_basic_user_file /etc/nginx/.htpasswd; 

    location = /api/ { 
    auth_basic "off"; 
    } 

    ssl on; 
    ssl_certificate /etc/ssl/www_mydomain_dk.crt; 
    ssl_certificate_key /etc/ssl/www_mydomain_dk.key; 
    include /etc/nginx/ssl_common.conf; 

    root /var/www/www.mydomain.dk/deployed/current; 
    add_header Access-Control-Allow-Origin "https://www.mydomain.dk"; 
    add_header Access-Control-Allow-Origin "https://mydomain.dk"; 

    include /etc/nginx/common.d/top_common.conf; 
    include /etc/nginx/common.d/locations.conf; 

    location ~ \.php$ { 
    try_files $uri =404; 
    expires off; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    proxy_connect_timeout 2600s; 
    proxy_send_timeout 2600s; 
    proxy_read_timeout 2600s; 
    fastcgi_send_timeout 2600s; 
    fastcgi_read_timeout 2600s; 
    fastcgi_pass mydomain; 
    fastcgi_pass_request_headers on; 
    fastcgi_keep_conn off; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root${fastcgi_script_name}; 
    fastcgi_param MAGE_RUN_CODE base; 
    fastcgi_param MAGE_RUN_TYPE website; 
    } 

    location = /bridge_xcxcdd.php { 
    auth_basic off; 
    try_files $uri =404; 
    expires off; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    proxy_connect_timeout 2600s; 
    proxy_send_timeout 2600s; 
    proxy_read_timeout 2600s; 
    fastcgi_send_timeout 2600s; 
    fastcgi_read_timeout 2600s; 
    fastcgi_pass mydomain; 
    fastcgi_pass_request_headers on; 
    fastcgi_keep_conn off; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root${fastcgi_script_name}; 
    fastcgi_param MAGE_RUN_CODE base; 
    fastcgi_param MAGE_RUN_TYPE website; 
    } 

location = /api { 
     auth_basic off; 
     try_files $uri =404; 
     expires off; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     proxy_connect_timeout 2600s; 
     proxy_send_timeout 2600s; 
     proxy_read_timeout 2600s; 
     fastcgi_send_timeout 2600s; 
     fastcgi_read_timeout 2600s; 
     fastcgi_pass mydomain; 
     fastcgi_pass_request_headers on; 
     fastcgi_keep_conn off; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root${fastcgi_script_name}; 
     fastcgi_param MAGE_RUN_CODE base; 
     fastcgi_param MAGE_RUN_TYPE website; 
     } 

} 
+0

,你必須張貼完成配置試過。這不會。 –

+0

當然。我已經添加完整的代碼現在:-) –

回答

1

嗯,我試過很多CONFIGS的最後一個制定。主要學習的不是在服務器塊中放置基本身份驗證,而是使用位置塊。然後,而不是調用外面的PHP,使用嵌套塊,所以限制可以繼承。

下面我將展示其做這項工作一回聲僅結構,你只需要修改你的配置在這種風格

events { 
    worker_connections 1024; 
} 
http { 
    server { 
     listen 80; 
     satisfy any; 

     location/{ 
      auth_basic "Restricted"; 
      auth_basic_user_file /var/www/html/.htpasswd; 
      echo "Restricted URL"; 

      location /api/ { 
       auth_basic "off"; 

       echo "you reach /api"; 

       location ~ \.php$ { 
        echo "You reached unauthenticated php"; 
       } 
      } 

      location ~ \.php$ { 
       echo "You reached authenticated php"; 
      } 
     } 

     location ~ \.php$ { 
      echo "You reached php"; 
     } 
    } 
} 

下面是我的測試

$ curl -u tarun:tarun localhost/abc/test.php 
You reached authenticated php 

$ curl -u tarun:tarun localhost/test.php 
You reached authenticated php 

$ curl localhost/test.php 
<html> 
<head><title>401 Authorization Required</title></head> 
<body bgcolor="white"> 
<center><h1>401 Authorization Required</h1></center> 
<hr><center>openresty/1.11.2.2</center> 
</body> 
</html> 

$ curl localhost/api/test.php 
You reached unauthenticated php 

$ curl localhost/api/test 
you reach /api 
+0

工程就像一個魅力,非常感謝你!不能說,謝謝你! –