I would like to run a rails application (redmine, actually) in a subdirectory off my domain. SOmething like http://foobar.com/redmine. Redmine is running as a stand-alone passenger instance that I would like to proxy requests to.
passenger start -a 127.0.0.1 -p 8000 -e production
I can confirm that the app is running if I access it locally from the server.
lynx http://127.0.0.1:8000/
Now I can't figure out how to get Apache to serve the app properly. This is what I have, but it doesn't work quite right:
Alias /redmine /home/redmine/www/redmine-1.2/public
<Directory /home/redmine/www/redmine-1.2/public>
allow from all
ProxyPass http://127.0.0.1:8000
ProxyPassReverse http://127.0.0.1:8000
</Directory>
It serves static assets fine from the public folder but doesn't seem to proxy requests properly. Everything returns 403. Apache log:
client denied by server configuration: proxy:http://127.0.0.1:8000
Figured it out. Apache config:
<Location /redmine>
Order deny,allow
Allow from all
ProxyPass http://127.0.0.1:8000
ProxyPassReverse http://127.0.0.1:8000
</Location>
Then add this line to config/environment.rb:
config.action_controller.relative_url_root = "/redmine"
Related
Couldn't find a question that had this specific setup, so was having trouble making some of the other answers work in my situation.
I have a CentOS server running a PHP-based website with Apache as the web server (working fine). I'm trying to now deploy a Flask-based app (using Gunicorn proxied through Apache) on a different port.
In my main httpd.conf file I have:
<IfModule proxy_module>
# Include the proxy information for VMS Flask Application
Include conf/extra/httpd-foo.conf
</IfModule>
And in my httpd-foo.conf file I have:
ProxyPreserveHost On
ProxyPass /foo http://localhost:8000/
ProxyPassReverse /foo http://localhost:8000/
Timeout 2400
ProxyTimeout 240
PHP website runs at: https://myphpwebsite.com
I'd like the Flask app to run at: https://myphpwebsite.com/foo
The problem I'm encountering is when I visit the Flask URL, is I encounter 2 issues. First, if I don't include a trailing slash after "foo", I get a 404 (because that directory doesn't actually exist in the real web directory. The second issue is that all my Flask routes assume "/" is "root", which it is not now. I don't know how to tell Flask that all routes should have "/foo" pre-pended to them.
Is this possible?
-- Some additional info --
I've tried running the gunicorn command with the "-E" option to tell it the SCRIPT_NAME which seemed to help only for the main page:
gunicorn app:app -b 0.0.0.0:8000 -t 180 -e SCRIPT_NAME=/foo -w 4
Currently, if I visit https://myphpwebsite.com/foo/ it results in a 500 Internal Server Error. I can see that my "not logged in" redirect appears to work and takes me to https://myphpwebsite.com/foo/login properly, but again it's just resulting in a 500 error.
I have kind of the same setup (apache, php, gunicorn, flask), and what works for me is to use VirtualHost and embed the ProxyPass in a Location-directive. So my conf-file looks something like
<VirtualHost *:80>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
<Location "/foo">
ProxyPass "http://127.0.0.1:8000/"
ProxyPassReverse "http://127.0.0.1:8000/"
</Location>
</VirtualHost>
This way, calls to https://mydomein.com/ are managed by Apache (managing php als always), and all the requests done to https://mydomein.com/foo are being delegated to GUnicorn (listening on port 8000).
I need to configure Jenkins behind Apache. For this purpose I installed Apache 2.2 using httpd-2.2.25-win32-x86-openssl-0.9.8y.msi.
Now I have configured jenkins with -
--httpPort=8084 --prefix=/jenkins (inside jenkins.xml)
The securityRealm for Jenkins is (I am using LDAP authentication):
<securityRealm class="hudson.security.LDAPSecurityRealm" plugin="ldap#1.11">
<server>ldap://ldap.myserver.com:1234</server>
<rootDN>DC=blah-blah,DC=blah</rootDN>
<inhibitInferRootDN>false</inhibitInferRootDN>
<userSearchBase></userSearchBase>
<userSearch>SAMAccountName={0}</userSearch>
<groupSearchFilter></groupSearchFilter>
<groupMembershipStrategy class="jenkins.security.plugins.ldap.FromGroupSearchLDAPGroupMembershipStrategy">
<filter></filter>
</groupMembershipStrategy>
<managerDN>email#mycompany.com</managerDN>
<managerPasswordSecret>XXXX</managerPasswordSecret>
<disableMailAddressResolver>false</disableMailAddressResolver>
<displayNameAttributeName>displayname</displayNameAttributeName>
<mailAddressAttributeName>mail</mailAddressAttributeName>
<userIdStrategy class="jenkins.model.IdStrategy$CaseInsensitive"/>
<groupIdStrategy class="jenkins.model.IdStrategy$CaseInsensitive"/>
</securityRealm>
The name of the server where Apache and Jenkins are hosted is : http://abchost/.
Jenkins is hosted at : http://abchost:8084/jenkins.
Now I need to configure Apache server in such a way that, when I enter http://abchost/jenkins in browser it a Proxy should work in between and it should forward the request to http://abchost:8084/jenkins and again, get the result from jenkins and display the result at : http://abchost/jenkins.
For this I have configured Apache like this:
NameVirtualHost abchost:80
Listen 80
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes On
<VirtualHost *:80>
ServerName abchost.com
ServerAdmin admin#abchost.com
ProxyPass /downloads !
Alias /downloads "d:\myPath1"
<Directory "d:\myPath2">
# Don't allow editing the main repository site.
Options -Indexes
</Directory>
<Directory "d:\myPath3">
# Remove 'Parent Directory' link from the site.
# IndexIgnore ..
#
Options +Indexes
# List file names which will be opened automatically when the folder is opened.
DirectoryIndex index.html toc.html
IndexOptions FancyIndexing HTMLTable FoldersFirst SuppressDescription
</Directory>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Jenkins via HTTP.
ProxyPass /jenkins/ http:/abchost:8084/jenkins/ nocanon
ProxyPassReverse /jenkins http://abchost:8084/jenkins/
</VirtualHost>
After this configuration, I am able to login in jenkins using http:/abchost:8084/jenkins/, but, not using http:/abchost/jenkins/.
Point to note is:
When I am logging in http:/abchost/jenkins/ using proper user id and pswd, it looks like the page refreshes and blank login page appears again.
When I am logging in http:/abchost/jenkins/ using wrong user id and pswd combination, it shows message that LDAP authentication failed.
Can anyone please enlighten me?
Thanks in advance!
I can't believe that it turned out to be so difficult, but I need to be able to run my rails app at localhost/rails_app for development reasons, without breaking other applications I have. (localhost/php_app, for example)
I've followed a lot of tutorials, but I still can't get it working.
I have passenger installed and I think the missing step is to properly configure a VirtualHost.
(Mac OS X, Rails 4, Apache)
Edit: The big problem is that I can't run in localhost:3000 or any other port
Edit2:
With this in the apache configuration file:
<VirtualHost *:80>
ServerName localhost
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /my_rails_app/ >
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
The application runs on localhost/my_rails_app/ but it still uses localhost/ as the base url, missing every asset and making all the links wrong.
First off, on a local system you can just use the built-in test server that comes with Rails. Here's a virtual host that I use on a ubuntu server to run Rails:
<VirtualHost *:80>
ServerName errandlist.com
ServerAlias www.errandlist.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/errandlist/public
RailsEnv production
<Directory /var/www/errandlist/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
And you are going to need to enable Passenger in your httpd.conf:
# Ruby Passenger support
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.19
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-1.9.3-p448/ruby
It will be very similar on OSX, your versions may vary.
Edit: here's a question about running the test server on port 80: How to run rails s -p80 on 80 port?
I just use this script to run on localhost from the command line for debugging purposes for a project known as "priority_tree":
c:\ruby\bin\ruby C:\web\priority_tree\script\server -e test -p 3000
Then just open up IE or Edge with http:\localhost:3000 to test the program's operation.
You have to have dns setup to access a sql server or other database instance if you use it, but otherwise this should work.
I've been working on a Perl Mojolicious project that uses websockets. I'm wanting to launch it on a shared server running apache and use proxyPass and proxyPassReverse to make the url prettier for my Mojolicious code running with Hypnotoad.
I have it set up as follows.
Apache url:
mydomain.com
Hypnotoad url:
mydomain.com:8080
With the following apache entry I can reverse proxy the Hypnotoad server to
project.mydomain.com
apache.conf entry
<VirtualHost *:80>
ServerName project.mydomain.com
DocumentRoot /var/www/project
<Directory /var/www/project/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://mydomain.com:8080/ keepalive=On
ProxyPassReverse / http://mydomain.com:8080/
RequestHeader set X-Forwarded-HTTPS "0"
</VirtualHost>
However my websocket requests give a 404 error when I use:
ws://project.mydomain.com/get-data
and a 302 error when I use:
ws://mydomain.com:8080/get-data
I guess this wouldn't be a problem is the websocket didn't check for authentication, but they use Mojolicious routes to check that you can post via the websocket.
From what I can see Apache doesn't support reverse proxying websockets. In apache/httpd conf files.
Has anyone found a usable solution to this using Apache that is stable for a production environment?
In March a patch was committed to the Apache trunk by Jim Jagielski which allows websockets to be proxied correctly. The patch adds a new submodule called proxy_wstunnel which allows mod_proxy to work with the "ws" and "wss" protocols.
The module is not yet in any official Apache releases (as of June 8th 2013), so you will need to compile it yourself. Voyageur's blog describes the process for Apache 2.2, but it should be easier for Apache 2.4
Apache httpd 2.4.6 includes proxying websocket requests.
I dont have much experience neither in Node.js not in socket.io, thus maybe I will ask silly questions and sorry for that first of all.
I am trying to do following:
Installed node on ubuntu where I have apache also installed.
Created virtual host in apache and set it as proxy to node. My conf file looks like:
<VirtualHost *:80>
ServerAdmin giorgi#omedia.ge
ServerName node.aidemo.info
ServerAlias www.node.aidemo.info
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://127.0.0.1:8080
ProxyPassReverse http://127.0.0.1:8080
</Location>
</VirtualHost>
Have created simple js file for server (first server example in socket.io website) and started server from cli with command: node server.js.
It starts perfectly and listens to 8080
Created another virtualhost where I put clientside index.html (also from first example in socket.io). At first I had problem (and actually main problem is this), browser couldn't resolve path /socket.io/socket.io.js. Then I went to the url (http://localhost:8080/socket.io/socket.io.js) from lynx locally from terminal, downloaded that js and put locally with virtualhost near index.html. After this, browser could resolve that request, but I have error when socket.io.js itself is trying to get the url:
http://localhost:8080/socket.io/1/?t=1347623348836
Do you have any ideas how can I solve this problem?
My main goal is to have web url from which I can access my node server and talk with it with socket.io - for example to create very simple chat.
I hope I was clear.
Thank you everyone who will try to help.
I am using express + socket.io and they are listening on port 3001. And I want http://example.com/folder to redirect to my Express app listening on port 3001 (i.e, to http://localhost:3001, server-side).
I have done the following.
The .html file has this:
<script src='/folder/socket.io/socket.io.js'> </script>
<script>
var socket = io.connect('http://example.com', {resource: 'folder/socket.io'});
...
</script>
And my apache2 conf looks like this:
ProxyPreserveHost On
ProxyPass /folder/ http://localhost:3001/
ProxyPassReverse /folder/ http://localhost:3001/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /folder/>
allow from all
</Location>
Note that it requires the module proxy_http to be enabled. To enable it, run this command:
sudo a2enmod proxy_http; service apache2 restart
If you put socket.io.js file locally near your index.html file, it will not resolve the problem because you probably didn't change the url in your socket var in main.js file, look at:
var socket = io.connect();
in your main.js/index.html (script)
replace with:
var socket = io.connect(httpprotocol+hostname+httpport);
My code source look like this:
var socket = io.connect('https://192.168.43.187:8443/');
http://localhost:8080 is obviously not going to be available to anything outside of your server.
The client-side javascript's io.connect() should be connecting to http://node.aidemo.info so that apache can send that off to Node.
http://node.aidemo.info:8080 might also work if you've opened up port 8080.