linux smb 服务端配置

1. 安装

sudo apt-get install samba  

2. 修改默认配置

sudo vim /etc/samba/smb.conf 

global 选项中添加一条:

 security = user


   comment = share test
   browseable = yes
   path = /home/wukt/tools/mount/
   read only = no

3. 设置用户


sudo smbpasswd -a wukt
# 输入密码, 可以不和登录密码一样


sudo service smbd restart

4. 连接


sudo mount.cifs // /mnt/test_amount -o username=wukt

get the real Client IP in django using nginx

Nginx is proxying the request to Django(maybe uwsgi) for you, so any request that reaches Django will look from localhost.

Change nginx config:

location / {
    proxy_pass http://frontends;
    proxy_pass_header Server;
    proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header REMOTE_ADDR $remote_addr;

and in django can get real client ip :

ip = request.META.get('HTTP_X_FORWARDED_FOR') or request.META.get('REMOTE_ADDR')

How to use Let’s Encrypt DNS challenge validation?

Currently it is possible to perform a DNS validation also with the certbot LetsEncrypt client in the manual mode. Automation is also possible (see below).

Manual plugin

You can either perform a manual verification – with the manual plugin.

certbot -d --manual --preferred-challenges dns certonly

Certbot will then provide you an instructions to manually update a TXT record for the domain in order to proceed with the validation.

Please deploy a DNS TXT record under the name with the following value:


Once this is deployed,
Press ENTER to continue

Once you have updated DNS record, press Enter, certbot will continue and if LetsEncrypt CA verifies the challenge, certificate is issued as normally.

You may also use a command with more options to minimize interactivity and answering certbot questions. Note that manual plugin does not yet support non-interactive mode.

certbot --text --agree-tos --email [email protected] -d --manual --preferred-challenges dns --expand --renew-by-default  --manual-public-ip-logging-ok certonly

The renewal does not work with the manual plugin as it runs in non-interactive mode. More info at official Certbot documentation.

Update: manual hooks

In the new Certbot version you can use hooks, e.g. --manual-auth-hook, --manual-cleanup-hook. The hooks are external scripts executed by Certbot to perform the task.

Information is passed in environment variables – e.g., domain to validate, challenge token. Vars: CERTBOT_DOMAIN, CERTBOT_VALIDATION, CERTBOT_TOKEN.

certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /path/to/dns/ --manual-cleanup-hook /path/to/dns/ -d

You can write your own handler or use already existing, there are many available, e.g., for Cloudflare DNS.

More info on official Certbot hooks documentation

Automation, Renewal, Scripting

If you would like to automate DNS challenges validation it is not currently possible with vanila certbot. Update: some automation is possible with the Certbot hooks.

We thus created a simple plugin that supports scripting with DNS automation. It’s available as certbot-external-auth.

pip install certbot-external-auth

It supports DNS, HTTP, TLS-SNI validation methods. You can either use it in the handler mode or JSON output mode.

Handler mode

In the handler mode, the certbot + plugin calls external hooks (a program, shell script, python, …) to perform the validation and installation. In practice you write a simple handler/shell script which gets input arguments – domain, token and makes the change in DNS. When handler finishes, certbot proceeds with validation as usual.

This gives you an extra flexibility, renewal is also possible.

Handler mode is also compatible with Dehydrated DNS hooks (former There are already many DNS hooks for common providers (e.g., CloudFlare, GoDaddy, AWS). In the repository there is a README with extensive examples and example handlers.

Example with Dehydrated DNS hook:

certbot \
    --text --agree-tos --email [email protected] \
    --expand --renew-by-default \
    --configurator certbot-external-auth:out \
    --certbot-external-auth:out-public-ip-logging-ok \
    -d "" \
    --preferred-challenges dns \
    --certbot-external-auth:out-handler ./ \
    --certbot-external-auth:out-dehydrated-dns \

JSON mode

Another plugin mode is JSON mode. It produces one JSON object per line. This enables a more complicated integration – e.g., Ansible or some deployment manager is calling certbot. Communication is performed via STDOUT and STDIN. Cerbot produces JSON object with data to perform the validation, e.g.,

certbot \
    --text --agree-tos --email [email protected] \
    --expand --renew-by-default \
    --configurator certbot-external-auth:out \
    --certbot-external-auth:out-public-ip-logging-ok \
    -d "" \
    --preferred-challenges dns \
    certonly 2>/dev/null

{"cmd": "perform_challenge", "type": "dns-01", "domain": "", "token": "3gJ87yANDpmuuKVL2ktfQ0_qURQ3mN0IfqgbTU_AGS4", "validation": "ejEDZXYEeYHUxqBAiX4csh8GKkeVX7utK6BBOBshZ1Y", "txt_domain": "", "key_auth": "3gJ87yANDpmuuKVL2ktfQ0_qURQ3mN0IfqgbTU_AGS4.tRQM98JsABZRm5-NiotcgD212RAUPPbyeDP30Ob_7-0"}

Once DNS is updated, caller sends new-line character to STDIN of the certbot to signalize it can continue with validation.

This enables automation and certificate management from the central management server. For installation you can deploy certificates over SSH.

For more info please refer to the readme and examples on certbot-external-auth GitHub.

EDIT: There is also a new blog post describing the DNS validation problem and the plugin usage.

EDIT: we currently work on Ansible 2-step validation, will be soon off.