I have nginx serving up my rails app, but I also have a separate 'thin' server running on another port to use with Faye (publish / subscribe gem).
So I believe that since all requests are going through nginx (right?), I can't just call myapp.com:9292 if the thin server is setup on that port, even if I use the myapp.com host rather than localhost for the thin server, because its not routed through nginx.
If I have the thin server running at 0.0.0.0:9292, what would I need to add to my nginx conf to route pings to myapp.com:9292 to 0.0.0.0:9292?
Actually you can - just call example.com:9292 - , because Nginx is listening to port 80 only, and sometimes 443
Unless you add another server block that listens to 9292 explicitly, the example.com:9292 should pass directly to your 'thin' server
Related
I am following a tutorial and have compiled a .net standalone app and sent it to my Ubuntu 16.10 server. Now I am running the app and everything seems to work correctly
$ ./MvcMovie
Hosting environment: Production
Content root path: /home/nnkuu/CEPublished/publish
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
But when I try to access the server through my web browser on http:// SERVER_IP:5000, the browser cannot establish the connection. What am I doing wrong?
The problem is that the server is listening on http://localhost:5000. That means that if you access the app from the same machine as http://localhost:5000, it will work, but it won't work if you access it from another machine.
What you need to do is to change the URL the app is listening on. The simplest way is to add the following line to the WebHostBuilder setup in your main method:
.UseUrls("http://*:5000")
I solved the problem by making nginx function as a proxy that forwards traffic from port 80 on the external interface to port 5000 on the internal interface where the .net application is listening. This was done by running nginx with the following configuration file:
# Default server configuration
#
server {
listen 80;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name <server_name or IP address>;
location / {
proxy_pass http://127.0.0.1:5000;
}
}
Most of the tutorials out there show how to configure nginx web server as a proxy to a unicorn ruby application server when they are on the same server; a result is that they both communicate via unix sockets. How can I configure both of them if they are on different servers.
Unicorn designed to serve fast clients only:
unicorn is an HTTP server for Rack applications designed to only serve
fast clients on low-latency, high-bandwidth connections and take
advantage of features in Unix/Unix-like kernels. Slow clients should
only be served by placing a reverse proxy capable of fully buffering
both the the request and response in between unicorn and slow clients.
How does it work within load balancing between multi nodes environment? The answer is to have application nodes Nginx+Unicorn (connect via Unix Domain Socket) and top level Nginx as load balancer on separate node.
The basic setup is as follows:
In your unicorn config you'll want to listen to a TCP port rather than a unix socket:
listen 80, :tcp_nopush => true
Likewise, in your Nginx configuration simply proxy requests to a remote server:
upstream backend {
ip_hash;
server backend1.example.com;
server backend2.example.com;
server backend3.example.com down;
server backend4.example.com;
}
You should also checkout http://unicorn.bogomips.org/examples/nginx.conf for unicorn-tailored nginx configuration.
I am integrating Plivo in to my application(Ruby/Rails) and I would like to setup the router to point to my local dev environment for the callback. I have setup my controller method: plivo/receive_sms and the associated route in routes.rb
My question is: How do I setup my router(NETGEAR) to receive the callback for localhost:3000/plivo/receive_sms from Plivo?
I have tried forwarding port 80 to my local IP (192.168.1.20) But that did not work.. So I added ports 3000 - 8080 with no success.
That should work:
Make sure you are forwarding external port 80 to your local port 3000.
Make sure the Plivo is configured with your OUTGOING public IP address as the call back URL hostname. (google for "What is my ip"? and google will tell you)
If that doesn't work, perhaps your computer is firewalled? Or your router / ISP firewalls port 80?
If #3 is the case, then try forwarding port 3000 to your local port 3000, but then you have to be able to change the callback URL (#2) to use port 3000.
Or - try:
localtunnel.me
localtunnel gem
PageKite
ShowOff
https://pagekite.net/2011-04-20/PageKite_meets_Showoff
http://devblog.avdi.org/2012/04/27/http-forwarding-services-for-local-facebook-development/
Or if you have access to a server thats sits somewhere on the internet, there are gems similar to local tunnel that will use your own server to do the proxying.
Or you can do it manually with SSH using the -R or -L option (I forget which).
Using nginx and phusion passenger to host site http://example.com and is running fine.However, I want to be able to forward http://example.com:3000 to the webrick server raise by running command rails s. How do i do that ?
I have a Rails app that is running on port 8080 that I need to trick to think it's running on port 80.
I am running Varnish on port 80 and forwarding requests to nginx on port 8080, but when the user tries to login with OmniAuth and the Devise gem generates a url to redirect back to the server, it thinks its on port 8080 which then the user will see.
Is there any way to trick the Rails app to hard code the port as 80 (I would think it's a bad practice), or have nginx forward the request as if it's running on port 80?
Since I am not running a nginx proxy to the Rails app I can't think of a way to trick the port.
Has anyone ran into this issue before, if so what sort of configuration is needed to fix it?
Thanks in advance!
EDIT:
Both nginx and Varnish are running on the same server.
I have the same setup with Varnish on port 80 and nginx on port 8080 and OmniAuth (no Devise) was doing exactly the same thing. I tried setting X-Forwarded-Port etc in Varnish and fastcgi_param SERVER_PORT 80; in nginx, both without success. The other piece in my setup is Passenger (which you didn't mention) but if you are indeed using Passenger then you can use:
passenger_set_cgi_param SERVER_PORT 80;
(The docs say you can set this in an http block but that didn't work for me and I had to add it to the server block.)
http://modrails.com/documentation/Users%20guide%20Nginx.html#passenger_set_cgi_param
Set up X-Forwarded-Port in Varnish. See this example and the other results from a Google search for "varnish x-forwarded-port".
You must also, of course, set up X-Forwarded-For and X-Forwarded-Proto.
The headers X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Port are a way for HTTP reverse proxies such as Nginx, Squid, or Varnish to communicate to the "back-end" HTTP application server, your Rails application running in Thin or Unicorn, who the user actually is and how the user actually connected.
For example, suppose you have Nginx in front of your Rails application. Your Rails application was booted with Thin and is listening on 127.0.0.1:8080, while Nginx is listening on 0.0.0.0:80 for HTTP and 0.0.0.0:443 for HTTPS. Nginx is configured to proxy all connections to the Rails app. Then your Rails app will think that any user's IP address is 127.0.0.1, the port is 8080, and the scheme is http, even if the actual user connected from 1.2.3.4 and requested the page via https on port 443. The solution is to configure Nginx to set the headers:
X-Forwarded-For: 1.2.3.4
X-Forwarded-Scheme: https
X-Forwarded-Port: 443
and the Rails app should use these parameters instead of the default ones.
The same applies for whatever reverse proxy you use, such as Varnish in your case.
You can make a proxy and server it as whatever port you want.
Maybe with apache on top and passenger stand alone...
<VirtualHost *:80>
ServerName <name>
DocumentRoot /home/deploy/<name>
PassengerEnabled off
ProxyPass / http://127.0.0.1:<port>/
ProxyPassReverse / http://127.0.0.1:<port>/
</VirtualHost>
In shell:
passenger start -e staging -p 3003 -d
Your problem seems you're getting redirects to port 8080. The best solution would be to configure Rails (or the OmniAuth/Devise gem) to treat the requests as if they were fired on port 80 (but I have no idea how or if it is possible).
Like ablemike said; Apache has a great module for this (mod_proxy), with ProxyPassReverse it rewrites the redirects back to port-80 redirects. Better even, with mod_proxy_html it will replace port-8080 links in HTML pages with port-80 links.
If you only need to rewrite redirects, you can rewrite redirects in Varnish VCL with something like:
sub vcl_fetch {
...
#Rewrite redirect from port 8080 to port 80
if ( obj.http.Location ~ "^http://[^:]+:8080/.*" ) {
set obj.http.Location = regsub(obj.http.Location, ""^(http://[^:]+):8080(/.*)","\1\2");
}
}
(I think you have to replace obj with beresp if you use varnish >= 2.1)
If you have to rewrite HTML pages, this will be a lot harder to do completely correct with varnish.