By default rails uses localhost:3000 in development mode. This one is not written in any projects config files. I am currently trying to edit ./config/environments/development.rb file to use CORS.
There is host_and_port method which may be used in contollers to get the HTTP requests HOST value as defined in its heading (point me if I am wrong).
I can write my host:port in config files manually and change it as long as my development host and port changes... But I want to configure my development environment as rarely as possible, so I need to access host and port configurations in config files.
So... how do I access my HOST and PORT in config files?
Related
I'm using mod-mono for deploying an asp.net mvc application on Ubuntu Server 10.04. The following packages were installed: mono-apache-server4 libapache2-mod-mono apache2.
There are several blogs that configure mod-mono virtual hosts via the sites-available Apache configuration. For example, I could modify /etc/apache2/sites-available/default configuration like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
MonoApplications "/:/var/www"
MonoServerPath /usr/bin/mod-mono-server4
... more default configuration
But then there are also sites that advise to use an webapp file for mod-mono virtual host configuration. For example, I could modify /etc/mono-server4/debian.webapp like this:
<apps>
<web-application>
<name>default</name>
<vpath>/</vpath>
<path>/var/www/</path>
<vhost>127.0.0.1</vhost>
</web-application>
</apps>
Both approaches however need an apache site SetHandler mono configuration setting.
The only difference I noticed is that for sites configuration I have to explicitly define mod-mono-server4 (otherwise the system is trying to start a server2 instance which is not installed). When configured via sites configuration it also seems that there is an additional mono_server process spawned.
I guess I should go with the webapp option, but are there any "big" differences between this two approaches? Is webapp configuration distribution specific or why are there two options anyway?
Webapp config file approach can also be used with stand-alone XSP4, without the need of apache.
For example, you can run:
xsp4 --appconfigfile etc/mono-server4/debian.webapp
And you'll get XSP4 working with your webapp config file.
Is it possible to make requests for example with Savon through something like ssh-tunnel. I can run this stuff from my stage server whose IP is whitelisted in the service I'm sending requests to. But of course I want to do the development on my computer :P so is there any option to do that? I've already tried savon's proxy: option in many combinations such as
proxy: "http://name:password#my_stage_server.com"
etc. I'm using Ruby on Rails.
SSH tunnels are the way to go. They are easy to set up, use this in one terminal session:
ssh -L 8080:servicehost:80 myuser#stagingserver
Once established, leave it open. It'll open port 8080 on your localhost as a tunnel to the TCP service at host:443. Point savon to http://localhost:8080/some/url/to/service to access the service running on http://servicehost/some/url/to/service.
If you need this frequently, it's convenient to add it to your ssh config file, which is located at ~/.ssh/config. It's a plain text file, the example above would look like this:
Host staging
HostName hostname.domain
LocalForward 8080 servicehost:80
User myuser
With this configuration you can open the tunnel by simply issuing ssh staging. There are more options you could set, please refer to the MAN page for details.
Hostname resolution
Keep in mind that the hostname servicehost must be resolvable from your staging server, not your development machine. You can use IP addresses, too.
I generally run Grails 2.0 from my IDE but have been seeking to deploy an app to a remote Virtual Private Server (linux) where I installed Tomcat and Mysql. I create a production WAR file and copy it to the Tomcat webapps dir, where I can see Tomcat restart and after some "fixing" I see the application come up, adding minimal bootstrap entries into the MySql database fine.
However, I cannot connect to the Grails app (remotely). If I specify www.mydomain.com, I am (finally) able to reach the main Tomcat server "welcome page". I also reach Tomcat if I add a "/" at the end, not my grails app.
As such I'm tried putting in full controller paths that I know work on my dev machine, and then accessing them on the remote machine (note grails.serverURL is configured as http://www.mydomain.com). Doing this, I get
HTTP Status 404 -- The requested resource (/BareBones/bare/create) is not available.
This error is from a BareBones application I created, as I was having some problems with VPS available memory. In any case, on my dev machine I can reach the this BareBones app URL
http://localhost:8080/BareBones/bare/create
as expected. When I deploy, I get the same HTTP Status 404 error (resource not available) when I do:
http://www.mydomain.com/bare/create
In Config.groovy, in this BareBones app I've got the minimal change:
environments {
development {
grails.logging.jul.usebridge = true
}
production {
grails.logging.jul.usebridge = false
grails.serverURL = "http://www.mydomain.com"
}
}
In my Tomcat server.xml file I changed over from the default 8080/8443 ports to 80/443, but using either either set results in the same problem.
I'm probably missing an easy step, just don't know what it is.
P.S. When I deploy the sample.war file that comes with Tomcat (isn't Grails, just a hello-world servlet), it works. I'm able to access that at
www.mydomain.com/sample
Since I FTP'd sample.war from my computer to the server, it would appear to indicate my FTPs are good, and the routing to the server is right, narrowing this down to Grails & Tomcat.
Usually in dev mode Grails mounts, as you pointed out, the context of appName, i.e. http://localhost:8080/BareBones/ here.
But the path it mounts on tomcat is not up to Grails itself, it is wholly dependent on the Tomcat configuration and primarily the name of the WAR file.
Even if you have BareBones as your appName and you deploy it as ROOT.war then it will mount the root "/" context. If you deploy it as BareBones.war then it should mount the same dir as in dev mode.
Because sites are usually mounted as ROOT.war "/", I can recommend setting
grails.app.context = "/"
in your Config.groovy file which will make it so that you will use the root context path also in dev, i.e. http://localhost:8080/
This makes it simpler since both dev and production will now have identical relative paths to everywhere and only the hostname:port will change.
I have a dedicated machine I use for testing. At the moment it's running a Rails (2.3) app over Apache and Passenger. I would also like to simultaneously serve a Flask application using the same machine and a different url if possible. Here's what I currently have for my httpd.conf file:
<VirtualHost *:80>
DocumentRoot /path/to/rails-app/public
PassengerDefaultUser railsuser
RailsEnv testing
# .. some misc apache config
</VirtualHost>
How should I modify it to serve two different urls (on a local network) with one serving the Rails app and the other serving Flask? Thanks.
In your OP, you're setting the handling for the default url.
For your second virtual web server, just use a specific host name in the config that is a second host name for the same machine. This is called "name-based" virtual hosting. See wikipedia.
Remember that multiple hostnames can resolve to the same IP address.
You can use the full dns system if you want, just specify your local network address (192.168.xxx) -- the url will not work for machines not on your local network.
More info will be available at the webmasters SO site.
A post with instructions
I have a rails application running on Nginx which needs to serve files for download from another internal server. The internal server uses a dynamic url to generate the file for download, so it isn't a static file sitting in a folder. Both the rails server and server with the files are on the same LAN but only the rails server is open to the public on port 80.
Additionally the files that I'm wanting to serve are anywhere from 5GB - 200GB so I don't want to tie up the rails process for the whole download if that is possible. Is there a way to do this with Net::HTTP + send_data? Or perhaps some kind of Nginx proxy rule?
From inside the LAN you can download a file with a url like this:
http://username:password#192.168.0.5/export?uuid=1234567890
The problem is 1) there is no access control for that url, with the user / pass you can download any file you want by passing in it's uuid parameter and 2) the server is only LAN accessible.
I figured out the answer to this question by following the tutorial here: http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/
To handle the HTTP Basic authentication you need to add this line to your nginx config:
proxy_set_header Authorization "Basic BASE64_USER_PASS";
Where BASE64_USER_PASS is a base64 string of your username and password in the format "user:pass"