Last active
July 12, 2018 08:21
-
-
Save Howard-Chang/cdd2f03fde1b6a27db3b67ee2c508afb to your computer and use it in GitHub Desktop.
nginx-ldap-auth&nginx-auth-ldap& basic authenticate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
basic authenticate (lab:苗網ES4) | |
nginx.conf: | |
user nginx; | |
worker_processes 4; | |
error_log /var/log/nginx/error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
keepalive_timeout 65; | |
#gzip on; | |
include /etc/nginx/conf.d/*.conf; | |
} | |
conf.d/default.conf: | |
server { | |
listen 80; | |
server_name localhost; | |
#charset koi8-r; | |
#access_log /var/log/nginx/host.access.log main; | |
location / { | |
#root /usr/share/nginx/html; | |
#index index.html index.htm; | |
auth_basic "Basic Auth"; | |
auth_basic_user_file /etc/nginx/.htpasswd; | |
proxy_set_header X-FORWARDED-USER $remote_user; | |
proxy_pass http://localhost:5601; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
#location ~ \.php$ { | |
# root html; | |
# fastcgi_pass 127.0.0.1:9000; | |
# fastcgi_index index.php; | |
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; | |
# include fastcgi_params; | |
#} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
#location ~ /\.ht { | |
# deny all; | |
#} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reference: | |
https://sapser.github.io/devops/2016/07/22/nginx-ldap | |
https://www.jianshu.com/p/9f2da3cf5579 | |
https://github.com/nginxinc/nginx-ldap-auth | |
nginx.conf: | |
error_log logs/error.log debug; | |
events { | |
worker_connections 10240; | |
} | |
http { | |
proxy_cache_path cache/ keys_zone=auth_cache:10m; | |
upstream backend { | |
server 127.0.0.1:9000; | |
#server 127.0.0.1:5601; | |
} | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
server { | |
listen 8081; | |
location / { | |
auth_request /auth-proxy; | |
error_page 401 =200 /login; | |
proxy_set_header X-FORWARDED-USER $cookie_xuser; | |
#proxy_pass http://backend/; | |
proxy_pass http://localhost:5601; | |
} | |
location /login { | |
proxy_pass http://backend/login; | |
proxy_set_header X-Target $request_uri; | |
} | |
location = /auth-proxy { | |
internal; | |
proxy_pass http://127.0.0.1:8888; | |
proxy_pass_request_body off; | |
proxy_set_header Content-Length ""; | |
proxy_cache auth_cache; | |
proxy_cache_valid 200 10m; | |
proxy_cache_key "$http_authorization$cookie_nginxauth"; | |
proxy_set_header X-Ldap-URL "ldap://localhost:389"; | |
proxy_set_header X-Ldap-BaseDN "dc=xinhua,dc=org"; | |
proxy_set_header X-Ldap-BindDN "cn=Manager,dc=xinhua,dc=org"; | |
proxy_set_header X-Ldap-BindPass "9ol./;p0"; | |
proxy_set_header X-CookieName "nginxauth"; | |
proxy_set_header Cookie nginxauth=$cookie_nginxauth; | |
} | |
} | |
} | |
backend-sample-app.py: | |
enc = base64.b64encode(user + ':' + passwd) | |
self.send_header('Set-Cookie', 'nginxauth=' + enc + '; httponly') | |
self.send_header('Set-Cookie', 'xuser=' + user ) //加入這一行 | |
self.send_header('Location', target) | |
self.end_headers() | |
---------------------------------------------介接Winoc AD-------------------------------------------------- | |
nginx.conf: | |
error_log logs/error.log debug; | |
events { | |
worker_connections 10240; | |
} | |
http { | |
proxy_cache_path cache/ keys_zone=auth_cache:10m; | |
upstream backend { | |
server 127.0.0.1:9000; | |
#server 127.0.0.1:5601; | |
} | |
server { | |
listen 8081; | |
location / { | |
auth_request /auth-proxy; | |
error_page 401 =200 /login; | |
proxy_set_header X-FORWARDED-USER $cookie_xuser; | |
#proxy_pass http://backend/; | |
proxy_pass http://localhost:5601; | |
} | |
location /login { | |
proxy_pass http://backend/login; | |
proxy_set_header X-Target $request_uri; | |
} | |
location = /auth-proxy { | |
internal; | |
proxy_pass http://127.0.0.1:8888; | |
proxy_pass_request_body off; | |
proxy_set_header Content-Length ""; | |
proxy_cache auth_cache; | |
proxy_cache_valid 200 10m; | |
proxy_cache_key "$http_authorization$cookie_nginxauth"; | |
proxy_set_header X-Ldap-URL "ldap://163.19.163.232:389"; | |
proxy_set_header X-Ldap-BaseDN "DC=winoc,DC=server,DC=com"; | |
proxy_set_header X-Ldap-BindDN "CN=test1,OU=WINOC,DC=winoc,DC=server,DC=com"; | |
proxy_set_header X-Ldap-BindPass "test1"; | |
proxy_set_header X-CookieName "nginxauth"; | |
proxy_set_header Cookie nginxauth=$cookie_nginxauth; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reference:https://github.com/kvspb/nginx-auth-ldap/issues/207 | |
nginx.conf: | |
user nginx; | |
worker_processes 4; | |
error_log /var/log/nginx/error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
ldap_server ldap_local { | |
url "ldap://localhost/dc=xinhua,dc=org?uid?sub?(objectClass=posixAccount)"; | |
binddn "cn=Manager,dc=xinhua,dc=org"; | |
binddn_passwd "9ol./;p0"; | |
require group "cn=secretary,ou=group,dc=xinhua,dc=org"; | |
group_attribute "memberUid"; | |
group_attribute_is_dn off; | |
require valid_user; | |
satisfy all; | |
} | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
keepalive_timeout 65; | |
#gzip on; | |
include /etc/nginx/conf.d/*.conf; | |
} | |
------------------------------------------------------------------------------ | |
default.conf: | |
server { | |
listen 8000; | |
server_name localhost; | |
auth_ldap "Forbidden"; | |
auth_ldap_servers ldap_local; | |
location / { | |
root /usr/share/nginx/html; | |
index index.html index.htm; | |
proxy_set_header X-PROXY-USER $remote_user; | |
proxy_pass http://localhost:5601; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
#location ~ \.php$ { | |
# root html; | |
# fastcgi_pass 127.0.0.1:9000; | |
# fastcgi_index index.php; | |
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; | |
# include fastcgi_params; | |
#} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
#location ~ /\.ht { | |
# deny all; | |
#} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment