1.nginx 配置模板
server { listen 80; client_max_body_size 512M; proxy_set_header Connection ""; proxy_http_version 1.1; proxy_connect_timeout 300; proxy_read_timeout 300; access_log /var/log/nginx/ralph-access.log; error_log /var/log/nginx/ralph-error.log; location /static { alias /usr/share/ralph/static; access_log off; log_not_found off; expires 1M; } #location /media { # alias /var/local/ralph/media; # add_header Content-disposition "attachment"; #} location / { proxy_pass http://127.0.0.1:8000; include /etc/nginx/uwsgi_params; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}
假如想通过X-Forwarded-For获得用户ip,必须先使用proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 这样,用户就可以获得真实的ip。
参考:https://blog.51cto.com/gyj110/2056933
用一个例子演示会更清晰
![](/images/780-200-2.jpg)