i am working on AWS Elastic Beanstalk Instance, which runs Java application served through Nginx ( no load balancer in front, just a standalone instance ) I need to set cookie to catch client ip and client hostname. Is this possible to do it in nginx or should this be done in my Java code?
Below if my nginx configuration file:
location / { proxy_pass http://127.0.0.1:5000; proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade; proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
You can try playing around with nginxs add_header Set-Cookie.
IP address of client should be in $remote_addr and host in $Host.
You can try adding following in location block:
add_header Set-Cookie cip=$remote_addr;
add_header Set-Cookie chost=$Host;
For more control you can try
add_header Set-Cookie "cip=$remote_addr;Domain=example.com;Path=/;Max-Age=100000";
I didn’t tried it myself, I’m not sure is it correct, but test. I will try it myself but I’m out of my test server and can’t verify now. :)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.