Apache 2.2.15 with WSS proxy rules issue - ruby-on-rails

Having a problem with 2.2.15 Apache using wws (web socket) rules.
To get 2.2.15 Apache to support web socket, we followed this guide "http://notmyitblog.blogspot.ie/2014/03/websockets-support-for-apache-httpd.html" and have successfully created the module + added it to Apache.
At this point, Apache is throwing a 502 error when we try to access a page using this.
We are not sure where in the overall httpd.conf file this rule should go.
The aim is to configure a chatbot application that runs using ruby-on-rails.
Our application is split between an Application server running ruby-on-rails on puma (10.1.1.2) and this Apache server (10.1.1.1).
Our httpd.conf contains:
<VirtualHost 10.1.1.1:80>
Server Name hostname
ServerAlias www.our.url>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cable [NC,OR]
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* wss://10.1.1.2:3000%{REQUEST_URI} [P,QSA,L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://10.1.1.2:3000%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
<Location /cable>
Require all granted
ProxyPassReverse wss://10.1.1.2:3000/cable
ProxyPassReverseCookieDomain 10.1.1.2 www.our.url
</Location>
</VirtualHost>
Is this format correct? Are any other configuration changes needed for this to take effect?
Is there any sort of test that can be done at server level to verify that the ws is configured and working?

Related

laravel 5.1 only routing to home page, all other routes are coming 404 not found error, after hosting the local working site to the server

I have pushed my laravel 5.1 application to server. In localhost, it works properly. but in server , only the home page is coming, no other routes working. I get 404 not found not found error. jQuery-2.1.4.min.js:4 POST http://mydomainurl/login/validate_login 404 . I feel, it should traverse to http://mydomainurl/applicationName/login/validate_login. I dont know whats happening and where i have to update.
I have enabled mode rewrite in apache and my .htaccess of application's public/ directory is as below
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_URI} !^ RewriteRule ^(.*)$ /$1 [L] </IfModule>
I dont know much about .htaccess, but i copied from someone's answer. Please help
After doing all the above modifications,And surfing around net, it didnt work. Finally i understood that it may be because of url problem and just changed the url in ajax, like url: "<?php echo url();?>/login/validate_login", It started working amazingly. Only in local host simply, url: "login/validate_login", works.
Over all, things to be done are:
1: move public folder contents to your server's root folder(name it anything, eg: var/www/html/my_public). Update the .htaccess and index.php of it as explained in other answers. modify server.php, bootstrap/app.php if still didnt work. use url() with the calls. I achieved with this much :-)
The problem is probably caused by your virtualhost config file. It should have "AllowOverride All" directive^
<VirtualHost *:80>
ServerAdmin youremail#yahoo.com
ServerName yoursite.com
ServerAlias www.yoursite.com
DocumentRoot "/var/www/yoursite.com/public"
<Directory /var/www/yoursite.com/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

www to http resolve for Rails app on passenger

I am running a rails app on phusion passenger. I want to resolve all www addresses to http for SEO benefits.
I am using phusion along with the apache server and for performance benefits would like the redirect to be in the httpd.conf file instead of the .htaccess file. I added the redirect in the httpd.conf file but it redirects to the public folder of the application on every url request. I wrote to my hosting provider and got the following response:
Since passenger is configured for your rails application via .htaccess, the direct rules through htaccess will not work. But, htaccess directs will work fine with non rails applications.
If you really wish to redirect www.xyz.com to xyz.com, you have to add a code similar to the following in your application.
-------
before_filter :check_uri
def check_uri
if /^www/.match(request.host)
redirect_to request.protocol + request.host_with_port[4..-1] + request.request_uri
end
end
I think this is not good for performance of the application. Is there any way I can redirect from the httpd.conf file itself?
Here is the httpd.conf file:
This redirects www to the public folder instead of http
<Directory "/home/xyz">
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</Directory>
<VirtualHost 1.1.1.1:80>
SuexecUserGroup "#500" "#501"
ServerName xyz.com
ServerAlias www.xyz.com
ServerAlias webmail.xyz.com
ServerAlias admin.xyz.com
#DocumentRoot /home/xyz/public_html
DocumentRoot /home/xyz/public
DirectoryIndex index.html index.htm index.php index.php4 index.php5
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.xyz.com
RewriteRule ^(.*) https://xyz.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.xyz.com
RewriteRule ^(.*) https://xyz.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "xyz.com statistics"
AuthType Basic
AuthUserFile /home/xyz/.awstats-htpasswd
require valid-user
</Files>
Alias /dav /home/xyz/public_html
<Location /dav>
DAV on
AuthType Basic
AuthName "xyz.com"
AuthUserFile /home/xyz/etc/dav.digest.passwd
Require valid-user
ForceType text/plain
Satisfy All
RemoveHandler .php
RemoveHandler .php5
RewriteEngine off
</Location>
</VirtualHost>

Symfony 1.4 Error 400 on the home page in prod env (not in dev env)

I have made an tested an application on my computer and all is working fine (I used only the dev environment via the frontend_dev.php page).
When I deploy this application on the test server, I have the error 400 Bad Request below:
Bad Request
Your browser sent a request that this server could not understand.
I accessed to the website with the normal URL.
I'm using symfony 1.4 with doctrine (no others plugins are involved), wamp 2 (php 5.3, apache 2.0.59).
If I try to access the application with the dev environment, it works.
Try checking if the no_script property on your application setting.yml file. If should be set to False, clear cache and try again
Thank you very much Guiman. You have leaded me to the answer.
The no_script_name property wasn't the origin of the problem. Instead, I have my .htaccess in the web directory which was badly generated (I swear on my pet's head that I haven't edited this file before). Below is the file generated by symfony (the bold attribute isn't working within the code one, look at the last line):
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
And this is the updated one (again, look at the last line):
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ **/myApp/index.php** [QSA,L]
</IfModule>
I don't know what happened but I will check on the symfony website I there are similar issues.

How do I edit .htaccess to allow both rails and wordpress requests?

I want to run an instance of wordpress within my rails app. I currently have wordpress files housed in public/wordpress, but I need to configure my .htaccess file to allow both types of requests. How do I do that? currently, .htaccess is:
General Apache options
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)/!$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
ErrorDocument 500 "Application error Application failed to start properly"
You should start by adding this to the .htaccess in your public folder:
RewriteCond %{REQUEST_URI} ^/wordpress.*
RewriteRule .* - [L]
However, this is not the whole story. You also need to edit /etc/apache2/sites-available/
with this addition (to tell Rails not to process anything in /blog as part of the app):
<Location /wordpress>
PassengerEnabled off
Also in /etc/apache2/apache2.conf you may need to tell Apache to make any directory index (e.g. wordpress/) execute an index.php file if there is one:
DirectoryIndex index.php

Rewriting rails url from port 3000?

i have an applicaiton that runs at actionengineers.com:3000. How do i reqwite the application to a subdomain or directory (actionengineers.com/myapp) without disturbing the main site of course. i tried to use .htaccess file but i allways get eror 404. here is the code in the .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.deep.actionengeneers.com$
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:3000%{REQUEST_URI}" [P,QSA,L]
Try this rule:
RewriteCond %{HTTP_HOST} =www.deep.actionengeneers.com
RewriteRule ^ http://127.0.0.1:3000%{REQUEST_URI} [P,L]
Now all requests to www.deep.actionengeneers.com are getting passed through to 127.0.0.1:3000 via proxy.

Resources