I’m using nginx to serve my sinatra application with unicorn. now as port 80 is already being used, I have setuped this app to listen on port 81. I can access it via IP:81 but to make a DNS entry, I need to forward http traffic from 81 to 80.
How to do this or clear me if, I’m making a wrong approach.
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!
Hi Kamal Nasser, actually this results in
* Restarting NGINX nginx nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
as my apache is using 80 already.
You can configure nginx to reverse proxy connections to port 81. If you’re going this route, it would make sense to allow access to your sinatra app through nginx only. Edit your app’s config and set it to listen on “127.0.0.1:8888” or any unused port above 1024 (any program that needs to listen on ports < 1024 must run as root which is not recommended for a website) and add the following nginx server block:
server {
listen 80;
server_name yourapp.com; # or server_name subdomain.yourapp.com;
location / {
proxy_pass http://localhost:8888;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# Enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
}
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.