Directory index forbidden by Options directive in ruby on rails - ruby-on-rails

I Configured SSL for rails app running with thin server in CentOS linux environment with apache. When I try to open my site using "https" I am getting Apache error page and I checked apache error logs and got the following error message
Directory index forbidden by Options directive.
I made some changes in /etc/httpd/conf.d/welcome.conf as
"Options -Indexes" TO "Options +Indexes"
then I am getting directory structure in browser.
Please help me to solve the issue
Update:
<VirtualHost *:80>
ServerName XXXX
ServerAlias www.XXXX.com
DocumentRoot XXXX
RewriteEngine On
<Proxy balancer://thinservers>
BalancerMember http://127.0.0.1:3000
</Proxy>
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://thinservers%{REQUEST_URI} [P,QSA,L]
ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog XXXX
CustomLog XXXX

Your included Apache configuration shows the HTTP virtual host as it's litening on port 80
<VirtualHost *:80>
HTTPS connects to a different virtual host defined on port 443 you will need to modify this virtualhost's configuration in order to change the way the HTTPS portion of your website behaves.

Related

nextjs in docker proxy via apache2 is giving 502 proxy errors

I have a nextjs application running in a docker. When I had the same docker image running locally and goto localhost:3000 everything runs perfectly.
I then deploy the image to the server and I have apache2 proxy passing to the site I get a broken landing page
I see I am getting errors like this
Request URL: http://example.com/_next/static/css/175964cd052c7c3f.css
Request Method: GET
Status Code: 502 Proxy Error
My apache setup is like this
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
ProxyPreserveHost On
ProxyRequests Off
ProxyVia On
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:3000 connectiontimeout=6000 timeout=6000
ProxyPassReverse / http://127.0.0.1:3000
CustomLog /var/log/apache2/mydomain.access.log combined
ErrorLog /var/log/apache2/mydomain.error.log
</VirtualHost>
Any help would be appreciated
Thanks
<VirtualHost *:80>
ServerName www.myservername.com
ServerAlias myservername.com
ErrorLog /var/www/myapp/log/error.log
CustomLog /var/www/myapp/log/requests.log combined
ProxyRequests on
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
It seems something was clashing. When I stripped it down to the above it works

How to configure redmine with https, in linux apache hosting server (i.e just host, bluehost)

How to configure redmine with https, in linux apache hosting server (i.e just host, bluehost).
normal http site is working. but it is not working in https. I am getting error like"Page not found".
What I usually do is to configure apache or nginx to redirect http to https
ServerAdmin webmaster#localhost
ServerName redmine.example.com
DocumentRoot /var/www/redmine/public
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
ErrorLog /var/log/apache2/redmine_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/redmine_access.log combined
don't forget the VirtualHost directives
you will need to enable ssl on your webserver

Thin server behind apache, stops working when I update code

I've got a rails app on a thin server as a Windows service that is proxied through Apache server. The app works correctly until I try to upload a new version of the project. Then I get a 502 bad gateway error. I tried restarting all of the services but no luck. It also looks like I can't hit it on port 3000 locally. Here's my apache httpd excerpt:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost localhost:80>
ServerName serverName
DocumentRoot "C:/locationOfAppDir"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost On
</VirtualHost>
<VirtualHost serverName>
ServerName serverName
DocumentRoot "C:/locationOfAppDir"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost On
</VirtualHost>
Protip to self: run bundle install when you add updated code with new gems.

Deploy 2 Sites on same Apache server

I need to deploy my Rails app to a server that is already serving a PHP site at its root. I can't touch the existing site, and I have to deploy my app at a sub-url or sub-domain, ie xx.xx.xx.xx/rails or rails.xx.xx.xx.xx.
The Apache config I normally use to deploy my app:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/RubyStack-3.2.5-0/projects/app_name/public"
<Directory "C:/RubyStack-3.2.5-0/projects/app_name/public">
Allow from all
Options -MultiViews
</Directory>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://app_balancers%{REQUEST_URI} [P,QSA,L]
<Proxy balancer://app_balancers>
BalancerMember http://localhost:3001/
BalancerMember http://localhost:3002/
</Proxy>
# Support for far-futures expires header
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
</VirtualHost>
How could I change this configuration to serve that folder from a sub-url or subdomain? A RedirectMatch won't work because it would also route people away from the existing PHP site, right?
Easiest way would be to do name-based virtual hosting, using a subdomain as you suggested. So where you write:
<VirtualHost *:80>
ServerName localhost
</VirtualHost>
Simply enter your subdomain instead:
<VirtualHost *:80>
ServerName mysubdomain.mycompany.com
</VirtualHost>
Apache should then separate any requests to that subdomain from the 'main' virtualhost automatically.
edit:
Alternatively it is possible to mount your rails app to a subdirectory as well (assuming you're using Passenger.) Here's an example based on my own local staging environment. I got this working by following the instructions at the Phusion website
<VirtualHost *:80>
ServerName localhost
# We will mount our application under http://localhost/myapp
RailsBaseURI /myapp
# This can be anywhere on the system, I just happened to use /home/www
<Directory /home/www/myapp>
# Here you can add any directives necessary for your app, like for example..
SetEnv GEM_HOME /home/user/.rvm/gems/ree-1.8.7-2012.02
</Directory>
</VirtualHost>
Now you have to do one more thing, and that's make /home/www/myapp a link to the public dir of the actual application. So let's say you have the application in your own homedir you would have to type this:
cd /home/www
ln -s /home/myuser/myapp/public myapp
If you then type ls -l it should show:
lrwxrwxrwx 1 myuser myuser 18 Jun 10 16:41 devb -> /home/myuser/myapp/public
I think that should be it.

Multiple domains, multiple vhosts, separate rails apps

I am trying to host multiple different rails apps on the same VPS using multiple domains. I am using Apache 2.2.17 on Ubuntu 10.10. For Apache, I have multiple vhost files so that I can enable and disable particular sites easily without needing to comment them out or delete them. In addition, I am also using mod_rewrite so that the multiple domains that go to the same rails app appear to go to the same URL so I don't take a hit with search engines as far as duplicate content.
I believe that my DNS is setup properly. For each of the domains, I have a www subdomain as well as some site-specific sub-domains, such as blogs, etc. The issue I am seeing is that Apache appears to matching the www subdomain immediately and not examining the additional URL behind it. Changing ServerAlias does nothing. For example, using my setup, if I enter davidheartsrachel.com, I properly reach my wedding website. However, if I use www.davidheartsrachel.com, I reach my other website, my software development business. The URL is not re-written; it stays as davidheartsrachel.com instead of afewguyscoding.com.
The only way I have been able to properly get it to work is to use mod_rewrite in the primary vhost file to redirect to the wedding website vhost file (you can see that I have that in the primary vhost file, but it is commented out for purposes of this question). This doesn't seem proper to me? Should I get another IP and do IP vhosts instead of name-based vhosts?
When I execute apachectl -S, I get the following:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
port 80 namevhost afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
port 80 namevhost blog.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:69)
port 80 namevhost lbbs.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:84)
port 80 namevhost davidheartsrachel.com (/etc/apache2/sites-enabled/davidheartsrachel.com:1)
port 80 namevhost dhr.afewguyscoding.com (/etc/apache2/sites-enabled/davidheartsrachel_staging:1)
Syntax OK
I notice that afewguyscoding.com is the default site - however, doesn't it have to do a full string match to determine the proper site?
Primary site's vhost file
<VirtualHost *:80>
ServerAdmin david.stites#afewguyscoding.com
ServerName afewguyscoding.com
ServerAlias davidstites.com, 5280software.com, milehigh-software.com, milehighsoftware.org
ServerAlias www.5280software.com, www.milehigh-software.com, www.milehighsoftware.org, www.davidstites.com, www.afewguyscoding.com
# this tells rails that it will run in production mode
# this is for rails < 3.x
RailsEnv production
DocumentRoot /var/www/afewguyscoding/current/public
DirectoryIndex index.html
# custom log file locations
# possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel alert
ErrorLog /var/www/afewguyscoding/current/log/error.log
CustomLog /var/www/afewguyscoding/current/log/access.log combined
# allows compression of text based mime.types
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
FileETag None
RewriteEngine On
# check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
RewriteCond %{REQUEST_URI} !^/ws/
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html
#RewriteCond %{HTTP_HOST} ^www.davidheartsrachel.com$
#RewriteRule ^(.*)$ http://davidheartsrachel.com$1 [L]
RewriteCond %{HTTP_HOST} ^www.davidstites.com$
RewriteRule ^(.*)$ http://www.afewguyscoding.com$1 [R=301,L]
<Directory /var/www/afewguyscoding/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# In case I ever need CGI
#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#<Directory "/usr/lib/cgi-bin">
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
#</Directory>
# how we can restrict access to documents from the local subnet
#Order deny,allow
#Deny from all
#Allow from 127.0.0.0/255.0.0.0 ::1/128
<Location /blog>
PassengerEnabled off
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info#afewguyscoding.com
ServerName blog.afewguyscoding.com
DocumentRoot /var/www/wpress
DirectoryIndex index.php
<Directory /var/www/afewguyscoding/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Wedding site's vhost file
<VirtualHost *:80>
ServerAdmin info#davidheartsrachel.com
ServerName davidheartsrachel.com
ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com
ServerAlias www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net
# this tells rails that it will run in production mode
# this is for rails < 3.x
RailsEnv production
# this is for rails >= 3.x
RackEnv production
DocumentRoot /var/www/davidheartsrachel/current/public
DirectoryIndex index.html
# Custom log file locations
# Possible values include: debug, info, notice, warn, error, crit, alert and emerg,
LogLevel alert
ErrorLog /var/www/davidheartsrachel/current/log/error.log
CustomLog /var/www/davidheartsrachel/current/log/access.log combined
# Allows compression of text based mime types
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
FileETag None
RewriteEngine On
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
RewriteCond %{HTTP_HOST} ^www.rachelanddavidwedding.com$
RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.rachelanddavidstites.com$
RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]
# Static cache
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteCond /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html -f
RewriteRule ^(.*)$ /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html [L]
<Directory /var/www/davidheartsrachel/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
If you can think of any more information that might be helpful, please, ask me to post it.
Edit:
Let me try to clear this up. In the most essential form, my question is: why does going to davidheartsrachel.com takes you to www.afewguyscoding.com and davidheartsrachel.com takes you to davidheartsrachel.com based on my configuration above
On my servers I don't define a primary site in my main httpd.conf file. I do all the virtual hosting in separate application specific conf files.
The only thing I have in my main httpd.conf is the line NameVirtualHost *:80
Here's a gist of a way you could try it. I pulled all the wedding site configuration out of your main site configuration. I set it so davidstites.com, afewguyscoding.com, and www.davidstites.com all redirect to www.afewguyscoding.com. The other domains (milehigh et al) are unaffected. I'm not sure where you wanted those to go.
All the wedding related domains redirect to www.davidheartsrachel.com.
I did notice what I think might have been a mess up in your main site configuration. Toward the end where you set your directory permissions you were using the /var/www/afewguyscoding/current/public directory instead of the /var/www/wpress that is the DocumentRoot. The correction I made there is on line 74 of the first document in that gist.
The answer is that I was incorrectly separating the entries under ServerAlias with a comma thusly:
ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com, www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net
It is supposed to be a space:
ServerAlias rachelanddavid.net rachelanddavidstites.com rachelanddavidwedding.com www.davidheartsrachel.com www.rachelanddavidstites.com www.rachelanddavidwedding.com www.rachelanddavid.net

Resources