I have given two different different websites names with same IP(192.168.1.142)
Now i am using both these for configuring the reverse proxy using nginx.
Is it ok whether i can run ?
Kindly suggest any problems if any that i might face in future.
Yes this is fine. Use different server {} blocks and the server_name option to specify which configuration is which:
server {
listen 80;
server_name domain.com;
# rest of domain.com options go here
}
server {
# this will be the default site on this host
listen 80 default_server;
server_name other.com;
# rest of other.com options go here
}
In practice, splitting the two server {} blocks into different files would make maintenance easier and is often the norm.
If you only want the sites to be available on that one IP, change the listen directive to:
listen 192.168.1.142:80;
Also if you want to use SSL/HTTPS then you may run into complications as you can only have one SSL certificate per IP address. There are solutions if this is the case.
Related
I've got several Docker containers acting as web servers on a bridge network. I want to use Nginx as a proxy that exposes a service (web) outside the bridge network and embeds content from other services (i.e. wiki) using server side includes.
Long story short, I'm trying to use the configuration below, but my locations aren't working properly. The / location works fine, but when I add another location (e.g. /wiki) or change / to something more specific (e.g. /web) I get a message from Nginx saying that it "Can't get /wiki" or "Can't get /web" respectively:
events {
worker_connections 1024;
}
http {
upstream wiki {
server wiki:3000;
}
upstream web {
server web:3000;
}
server {
ssi on;
location = /wiki {
proxy_pass http://wiki;
}
location = / {
proxy_pass http://web;
}
}
}
I've attached to the Nginx container and validated that I can reach the other containers using CURL- they appear to be working properly.
I've also read the Nginx pitfalls and know that using hostnames (wiki, web) isn't ideal, but I don't know the IP addresses ahead of time and have tried to counter any DNS issues by telling docker-compose that the nginx container depends on web and wiki.
Any ideas?
You must turn proxy_pass http://wiki; to proxy_pass http://wiki/;.
As I know, Nginx would take two different way with/without backslash at the end of uri. You may find more details about proxy_pass directive on nginx.org.
In your case, a backslash(/) is essential as a uri to be passed to server. You've already got error message "Can't get /wiki". In fact, this error message means that there is no /wiki in server wiki:3000, not in Nginx scope.
Getting better knowing about proxy_pass directive with/without uri would help you much.
I hope this would help.
Heroku custom domains
I've setup two custom domains for my Heroku app.
example.com example.com.herokudns.com
*.example.com wildcard.example.com.herokudns.com
Domain configuration
I configured my domain as follows:
I added a CNAME Record for * pointing to wildcard.example.com.herokudns.com.
Works fine.
I forwarded my URL using GoDaddy's Domain Forwarding tool, because I can only specify IP addresses as A records.
Problem
The domain forwarding points to example.com.herokudns.com. Unfortunately GoDaddy automatically prepends http://, so it actually does not open my app and instead shows a Heroku message:
There's nothing here, yet.
Goal
Setting up my GoDaddy root domain to point to my Heroku app.
Note: GoDaddy automatically added an A record for # pointing to >>++FWD1++<<
Cloudflare does the job!
Finally, I achieved my goal of using my naked domain as host by choosing CloudFlare to handle my DNS configuration.
Resources:
CloudFlare allows CNAME Records to be the naked domain
How CNAME Flattening works
Note: CloudFlare has a pretty good documentation and setup process, you just need to:
add your domain to CloudFlare
follow the CloudFlare setup guide
updating your nameservers (in my case GoDaddy) to point to CloudFlare
What did you set your DNS to forward to? I had this same problem, but solved this creating a Heroku DNS entry for www.myapp.com. Heroku creates a DNS target of www.myapp.com.herokudns.com.
Here is my setup:
DNS forwarding to www.myapp.com
DNS CName of www to www.myapp.com.herokudns.com
Heroku DNS added www.myapp.com
You can also achieve this by setting up a nginx server with docker in five minutes.
First follow the instruction on this link: https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71
Then add your nginx server ip to your A Record with host name #
In you nginx server you can use this code to redirect all traffic to your naked domain to www domain. Just replace all your-domain.com with your domain.
server {
listen 80;
server_name your-domain.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://www.your-domain.com;
}
}
server {
listen 443 ssl;
server_name your-domain.com;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
location / {
return 301 https://www.your-domain.com$request_uri;
}
}
In Setup Heroku and GoDaddy? allegutta solves the issue by masking the heroku-app-name domain with the .com domain. Instead of slooob.com.herokudns.com, use your original heroku app url ([heroku-app].herokuapp.com) and it should work. Just worked for me.
I have a Rails API and a web app(using express), completely separate and independent from each other. What I want to know is, do I have to deploy them separately? If I do, how can I make it so that my api is in mysite.com/api and the web app in mysite.com/
I've seen many projects that do it that way, even have the api and the app in separate repos.
Usually you don't expose such web applications directly to clients. Instead you use a proxy server, that forwards all incoming requests to the node or rails server.
nginx is a popular choice for that. The beginners guide even contains a very similar example to what you're trying to do.
You could achieve what you want with a config similar to this:
server {
location /api/ {
proxy_pass http://localhost:8000;
}
location / {
proxy_pass http://localhost:3000;
}
}
This is assuming your API runs locally on port 8000 and your express app on port 3000. Also this is not a full configuration file - this needs to be loaded in or added to the http block. Start with the default config of your distro.
When there are multiple location entries nginx chooses the most specific one. You could even add further entries, e.g. to serve static content.
While Svens answer is completely correct for the question given. I'd prefer doing it at the DNS level so that I can change the server to a new location just in case my API or Web App experience heavy load. This helps us to run our APIs without affecting WebApp and vice-versa
DNS Structure
api.mysite.com => 9.9.9.9 // public IP address of my server
www.mysite.com = > 9.9.9.9 // public IP address of my server
Since now you'd want both your WebApp and API to run on the same server, you can use nginx to forward requests appropriately.
server {
listen 80;
server_name api.mysite.com;
# ..
# Removed for simplicity
# ..
location / {
proxy_pass http://localhost:3000;
}
}
server {
listen 80;
server_name www.mysite.com;
# ..
# Removed for simplicity
# ..
location / {
proxy_pass http://localhost:8000;
}
}
Any time in future if you are experiencing overwhelming traffic, you can just alter the DNS to point to a new server and you'd be good.
What my question is how do i map all the instances with port 80 with appropriate identical sub domains using Phusion Passenger + Nginx under Debian 6 for the following scenario.
Note : i am newbie to ruby on rails and server hosting , i unable to express my vision as question , please forgive me if i am wrong or correct me.
Hi , i am having an one product developed using ruby on rails , going to host in an dedicated server with 32 GB Ram and 8 Core Server Processor. Each client should have seperate DB and separate rails instance. I am replicating - duplicating code for each client with separate folders and giving different database names and so each serving as an different instance. Basically Source code is same for all client but only database name differs, so i am putting source code into different folders and staring as an separate rails application for each client.
For Example:
I am having one primary temp domain
www.product.com
For each client i need to have separate sub domain mapped to same server with same port(80)
but with different rails instance name
www.client1.product.com
www.client2.product.com
www.clientn.product.com
As i know if i start rails instance , each will start at seperate port no's
client1 with start at port 3001
client2 with start at port 3002
client3 with start at port 3003
What my question is how do i map all the instances with port 80 with appropriate identical sub domains using Phusion Passenger + Nginx under Debian 6
if i access
www.client4.product.com , i need to get app running in port 3004
I hope you found the solution by now, but for the sake of stackoverflow archive I'm going to provide an answer.
Generaly meaning you should use reverse proxy (http://wiki.nginx.org/RubyonRailsMongrel) with nginx, while your upstream will be a passenger|thin|unicorn|puma|mongrel (pick your favorite) server runnning your dedicated rails application (I will use duplicated code in order to isolate your client running environment.) You'll be able to provide load balancing with this method.
Now, you stipulate the use of Passenger, you could use a really simple setup if you compile nginx with passenger extention. (go to http://www.modrails.com/documentation/Users%20guide%20Nginx.html for better explanation)
server {
listen 80;
listen [::]:80 default_server ipv6only=on; # please for a better world be IPv6 compliant !
server_name www.client1.product.com;
root /my/rails/app1;
passenger_enabled on;
}
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
server_name www.client2.product.com;
root /my/rails/app2;
passenger_enabled on;
}
.......
I've just deployed a Rails application using Capistrano under /home/username/app_name.
Now, I'm not quite sure on how to setup Nginx, I've followed this tutorial, http://coding.smashingmagazine.com/2011/06/28/setup-a-ubuntu-vps-for-hosting-ruby-on-rails-applications-2/comment-page-1/#comment-594321. I have this on my nginx.conf file, I modified the first server block I saw:
server {
listen 80;
server_name www.yourdomain.com;
root /home/johndoe/test_app/current/public;
passenger_enabled on;
...
}
But now, I'm not sure how to procede. What exactly is the server_name in the example above? And how should I access the application? I've tried typing in my ip address and nothing shows up. I'm using Linode by the way. And how do I set up the nameservers for my domain? Detailed explanations and tutorials would be very helpful. Thanks in advance!
server_name on Nginx is exactly the same as ServerName in Apache, i.e. the domain name you'd like to use for this directory (named virtual host).
With passenger set to on you should be able to access the application directly via the domain.