How can i parse apache2 config file using nokogiri or any other xml parser? I've tried to parse the file using Nokogiri::XML the following way:
parsed = Nokogiri::XML(File.open("/home/user/config"))
That didn't help. When trying to inspect the object using parsed.errors i get the following:
[#<Nokogiri::XML::SyntaxError: Start tag expected, '<' not found>]
Is there any gems or anything else to parse apache config, edit and save it?
UPD:
Here is my config file:
LoadModule passenger_module /home/user/.rvm/gems/ree-1.8.7-2012.02#gemset/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /home/user/.rvm/gems/ree-1.8.7-2012.02#gemset/gems/passenger-3.0.11
PassengerRuby /home/user/.rvm/wrappers/ree-1.8.7-2012.02#gemset/ruby
<VirtualHost *:80>
ServerAdmin user#localhost
RailsEnv staging
DocumentRoot /path_to_project/public
Alias /webdav /path_to_project/public/dir
Alias /webdav-some-dir path_to_project/public/dir/another_dir
ServerSignature On
<Directory path_to_project/public>
AllowOverride all
Options -MultiViews
AddDefaultCharset utf-8
</Directory>
<Location /webdav>
DAV On
AuthType Basic
AuthName "webdav"
AuthUserFile /var/www/project_name/passwd.dav
PassengerEnabled off
Require globalAdministrator
<Limit GET OPTIONS PROPFIND>
Require user username #valid-user
</Limit>
<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require user username #globalAdministrator
</Limit>
</Location>
<LocationMatch "/webdav/.+/.+/.+/.+/.+/.+">
<Limit PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require user username #valid-user
</Limit>
</LocationMatch>
<Location /webdav-some-dir>
DAV On
AuthType Basic
AuthName "webdav"
AuthUserFile /var/www/project_name/passwd.dav
PassengerEnabled off
Require globalAdministrator
<Limit GET OPTIONS PROPFIND>
Require user username #valid-user
</Limit>
<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require user username #valid-user
</Limit>
</Location>
<LocationMatch "/webdav-some-dir/.+/.+/.+/.+/.+">
<Limit PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require user username #valid-user
</Limit>
</LocationMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Apache config files are not valid XML. It has XML-like (most likely SGML-like) tags for grouping of options, but it's not in any way XML. Try the apache_config gem for parsing the config file; though it seems unmaintained.
Hash.from_xml(File.open("/path/to/config", "r").read)
If this doesnt work you schould also post the content of the config file here....
What are you trying to accomplish? I think your app should not be concerned about the apache setup it's running under...
Related
Situation is like this :
I have hosting company justhost.com
There I have main domain and two subdomains. First subdomain is with PHP
based webpage, but second is newly created and based on ruby on
rails.
I want such thing, before I am sure that newly created application on RoR is functioning well, keep old one up and running. But somehow when I want modify .htaccess file with code for RoR (source- https://my.justhost.com/cgi/help/rails#access ).
main htacces file located on root_page :
DirectoryIndex index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml index.htm home.htm default.htm index.fcgi default.html
# -FrontPage-
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthUserFile /home/ecotec11/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/ecotec11/public_html/_vti_pvt/service.grp
ErrorDocument 404 /404.shtml
AuthName ecotechno.lv
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
htacces file for RoR application:
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
#Change to your environment
RailsEnv production
RailsBaseURI /$HOME/$USER/eco
SetEnv GEM_HOME /
This is what I get :
http://gyazo.com/291394024c60284e315b04b3b91128f4 :
It seems that project can't find installed gems or valid rails installation. I tried to update rails installation, but now when it succeded there is no change at all.
Thanks
I need some help getting a Rails 3.2 app working in a sub-uri of a cPanel-configured Apache site. I've followed the steps from the Passenger docs and various blog posts. The root action renders fine, but every other request gives me a 404.
I think it is something in the Apache, not Rails, config, because it's not the Rails app's 404 page, and the 404s do not leave traces in the Rails log.
Here is the vhost section from httpd.conf, generated by cPanel:
<VirtualHost myip:443>
ServerName mysite.org
ServerAlias www.mysite.org
DocumentRoot /home/myuser/public_html
ServerAdmin webmaster#mysite.org
UseCanonicalName Off
Options -ExecCGI -Includes
RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
CustomLog /usr/local/apache/domlogs/mysite.org combined
CustomLog /usr/local/apache/domlogs/mysite.org-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User myuser # Needed for CPanel::ApacheConf
UserDir disabled
UserDir enabled myuser
<IfModule mod_suphp.c>
suPHP_UserGroup myuser myuser
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup myuser myuser
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RUidGid myuser myuser
</IfModule>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/mysite.org.crt
SSLCertificateKeyFile /etc/ssl/private/mysite.org.key
SSLCACertificateFile /etc/ssl/certs/mysite.org.cabundle
CustomLog /usr/local/apache/domlogs/mysite.org-ssl_log combined
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory "/home/myuser/public_html/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
Include "/usr/local/apache/conf/userdata/ssl/2/myuser/mysite.org/*.conf"
</VirtualHost>
Here is the current version of the include file I put together for the sub-uri:
RewriteEngine On
RewriteOptions Inherit
RailsEnv production
<Directory /home/myuser/public_html>
Options Indexes FollowSymLinks -MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
RackBaseURI /home/myrailsapp/current
<Directory /home/myuser/public_html/railsapp>
Options -MultiViews
</Directory>
/home/myuser/public_html/railsapp is a symlink to /home/myrailsapp/current/public
Here is /home/myrailsapp/current/public/.htaccess
RackBaseURI /railsapp
SetEnv GEM_HOME /usr/local/lib/ruby/gems
PassengerEnabled On
PassengerAppRoot /home/myrailsapp/current/
All files in /home/myrailsapp and /home/mysite are owned by myuser. (I'm not seeing any permissions errors.)
In my routes file:
resources :widgets
root :to => 'widgets#index'
When I navigate to https://mysite.org/railsapp it correctly displays the widgets index, including assets. When I go to https://mysite.org/railsapp/widgets or https://mysite.org/railsapp/widgets/index, I get the Apache 404, and no entry in the Rails log.
What am I missing?
It turns out .htaccess in /home/myuser/public_html was rewriting everything. Requests for /mysite/railsapp were exempted because it matched a directory name. I solved the problem by adding
RewriteEngine off
to /home/myrailsapp/current/public/.htaccess.
Adding RewriteEngine off to .htaccess does solve the problem.
In an attempt to serve my precompiled assets with Apache, per this Rails Guide I try to change this:
<VirtualHost *:82>
ServerName localhost
DocumentRoot "C:/RubyStack-3.2.5-0/projects/release_checklist/public"
<Directory "C:/RubyStack-3.2.5-0/projects/release_checklist/public">
Allow from all
Options -MultiViews
</Directory>
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
ProxyPreserveHost On
</VirtualHost>
To this:
<VirtualHost *:82>
ServerName localhost
DocumentRoot "C:/RubyStack-3.2.5-0/projects/release_checklist/public"
<Directory "C:/RubyStack-3.2.5-0/projects/release_checklist/public">
Allow from all
Options -MultiViews
</Directory>
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
ProxyPreserveHost On
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
</VirtualHost>
in my httpd.conf file. However, the Apache server won't start when the second option has been added. What am I doing wrong?
What error does it give you? Are you sure you have mod_expires compiled into apache and that the module is loaded?
Invalid command 'ExpiresActive', perhaps misspelled or defined by a module not included in the server configuration
Yeah, that's usually the error you get if you use a directive that's mapped to a module that isn't loaded (or just a mispelled directive, which appears the same to apache). You'll need to check httpd.conf and make sure the LoadModule expires_module modules/mod_expires.so line is not commented out, of if it's missing, to add it. Depending on your apache's version, the line can be slightly different.
I'm trying to get Ruby on Rails going on a Windows 2003 Server. I've installed the Mongrel service and Apache (and RoR, etc).
When I serve an app using just Mongrel, everything comes up perfectly.
So, now I am down to the Apache configuration... Apparently I can't seem to get that right. When I visit my pages, I am returned the correct HTML, but it's returned with the Content-Type set to text/plain instead of html or xhtml... In addition, If I try to get to one of the css pages, I get a 500 Internal Server error (served back as HTML, returned with the text/plain Content-Type).
Here is my Virtual Host file (Any help would be VERY VERY VERY appreciated!):
NameVirtualHost *:8080
#Proxy balancer section (create one for each ruby app cluster)
<Proxy balancer://myapp_cluster>
Order allow,deny
Allow from all
BalancerMember http://rails.localdomain.com:3010
#BalancerMember http://myapp:3011
</Proxy>
#Virtual host section (create one for each ruby app you need to publish)
<VirtualHost *:8080>
ServerName rails.localdomain.com
DocumentRoot c:/www/app/public/
<Directory c:/www/app/public/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ProxyRequests Off
ProxyPass / balancer://myapp_cluster
ProxyPassReverse / balancer://myapp_cluster
ProxyPreserveHost On
#SetOutputFilter INFLATE;DEFLATE
#SetOutputFilter proxy-html
#log files
ErrorLog c:/www/log/app_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog c:/www/log/app_access.log combined
#Rewrite stuff
RewriteEngine On
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://myapp_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate
#AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
#BrowserMatch ^Mozilla/4 gzip-only-text/html
#BrowserMatch ^Mozilla/4\.0[678] no-gzip
#BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
</VirtualHost>
OK, here's part of the answer. This part deals with the .css and .js files. Apparently it relates to trailing slashes... I had to remove some slashes and add some others...
Removed:
DocumentRoot c:/www/app/public
<Directory c:/www/app/public >
Added:
ProxyPass / balancer://myapp_cluster/
ProxyPassReverse / balancer://myapp_cluster/
Now I can pull up the .css and .js files just fine...
HOWEVER: I am still having the issue of Apache NOT sending the right headers. Right inside the HTML that I'm returning I have this:
But it's STILL returning text/plain (the DefaultType as set in the httpd.conf).
PLEASE, if anyone has any ideas, let me know!!!!!
Thanks
I heavily recommend a linux host for RoR. Unicorn and Passenger are way better tools than mongrel clusters. See github blog post about it.
I want to password protect all urls on my beta site at the moment. Except one url because it is called by flash and flash can't handle basic auth properly it seems. So i want to disable basic auth for that one url. This is my config in apache. Apache is a proxy for tomcat but that should not matter right ?
<IfModule mod_proxy_ajp.c>
ProxyRequests On
ProxyVia On
<Location /uploader>
Order allow,deny
Allow from all
ProxyPass ajp://localhost:8050/uploader
ProxyPassReverse ajp://localhost:8050/uploader
</Location>
<Location />
Order allow,deny
Allow from all
AuthType Basic
AuthName "Restricted area"
AuthUserFile /etc/apache2/passwd/site-access
Require valid-user
ProxyPass ajp://localhost:8050/
ProxyPassReverse ajp://localhost:8050/
</Location>
</IfModule>
SO my thinking is that if http://www.example.com/uploader is called then the first location config is should be matched and no auth is required.
This does not seem to work i always get asked for auth. Any ideas ?
regards
Peter Delahunty
Add Satisfy Any to the uploader location:
<Location /uploader>
Order allow,deny
Satisfy Any
Allow from all
ProxyPass ajp://localhost:8050/uploader
ProxyPassReverse ajp://localhost:8050/uploader
</Location>
This is documented in the Apache docs, but under the description of the Require directive.