Revisiting a closed topic. Web.Config to Caddy file

I saw this post: Convert web.config to Caddyfile and it works to a point, the whole CSS and what not works, but the admincp does not, and i was wondering if there was any fix to it as the post it belonged to got closed back in 2017.

Im using Vbulletin 5.5.1 and the only issue i have is the rewrite of the admincp of:

rewrite /admincp (
index.php?routestring={uri}
}

And i would love some help to get it working.

The old config was as is

Send css calls directly to the correct file VBV-7807

rewrite /css.php /core/css.php

Redirect old install path to core.

rewrite /install {
to /core/install
}

Main Redirect

rewrite {
ext !gif !jpg !jpeg !png !css
to {path} {path}/ index.php?routestring={uri}
}

Because admincp is an actual directory.

rewrite /admincp {
index.php?routestring={uri}
}

section

gzip # Ha ha.

section
Requires third-party plugin https://caddyserver.com/docs/expires
expires {
match .js$ 14d # 1209600 = 14 days
match .css$ 1y # 31536000 = 365 days - wow, seems a little long for CSS
match .(gif|jpg|jpeg|png|ttf|otf|woff|svg)$ 1m # 2592000 = 30 days#}

I was thinking about the fact that i could do

rewrite /admincp {
to /core/admincp
}

But that gives errors as well which i can’t seem to fix. As well to that fix, it gives me this error

Invalid Page URL. If this is an error and the page should exist, please contact the system administrator and tell them how you got this message.

Hi @Alaura, welcome to the Caddy community.

I remember taking a crack at that one, based off the .htaccess rather than the web.config. I don’t recall whether the OP ever confirmed if it worked or not.

Can you elaborate on which errors you’re getting? Try to quote the exact output when you try it with the rewrite to index.php.

The /admincp path definitely needs to be rewritten to the root index.php, see the original .htaccess posted in the earlier thread:

	# Because admincp is an actual directory.
	RewriteRule ^(admincp/)$ index.php?routestring=$1 [L,QSA]
1 Like

So with the whole index.php?routestring fix, i get the error

– Subject: Unit caddy.service has begun start-up
– Defined-By: systemd
– Support: systemd-devel Info Page
–
– Unit caddy.service has begun starting up.
Apr 14 19:02:14 vultr.guest caddy[9214]: 2019/04/14 19:02:14 /etc/caddy/sites-enabled/forums.fioregaming.com.conf:22 - Error during parsing: Wrong argument count or unexpected line ending after ‘index.php?routestring={uri}’
Apr 14 19:02:14 vultr.guest systemd[1]: caddy.service: control process exited, code=exited status=1
Apr 14 19:02:14 vultr.guest systemd[1]: Failed to start Caddy HTTP/2 web server.
– Subject: Unit caddy.service has failed
– Defined-By: systemd
– Support: systemd-devel Info Page
–
– Unit caddy.service has failed.
–
– The result is failed.

When i try to use that exact line in the config of caddy. As well as, i use the nginx example of setting up a includes folder to sites-enabled while having a symbolic link from sites-available so that i can save time if i need to disable a site or enable a site.

Ahhh!

Easy. This is why exact error messages are useful :smiley:

Looks like I made a mistake when I wrote out that original Caddyfile by hand. The syntax for the target inside a rewrite block is actually to [target], not just the target on its own.

So, instead of this:

# Because admincp is an actual directory.
rewrite /admincp {
    index.php?routestring={uri}
}

It should be this:

# Because admincp is an actual directory.
rewrite /admincp {
    to index.php?routestring={uri}
}

(like the rewrite above it has).

2 Likes

So, it worked to redirect me to the admin cp, but it then redirects me for some reason to the main page giving me the error

Invalid Page URL. If this is an error and the page should exist, please contact the system administrator and tell them how you got this message.

I would give the url to my site for you to see, idk how i would make you a admin but it would allow you to see what i mean. Does this with anything admin related.

Heres the process as well step by step in pictures. To reproduce.

Step 1
Step 2
Step 3

And heres the config itself as well.

forums.fioregaming.com {
root /srv/www/forums.fioregaming.com/public_html/
gzip
fastcgi / /run/php-forums.fioregaming.com.sock php

Send css calls directly to the correct file VBV-7807

rewrite /css.php /core/css.php

Redirect old install path to core.

rewrite /install {
to /core/install
}

Main Redirect

rewrite {
ext !gif !jpg !jpeg !png !css
to {path} {path}/ index.php?routestring={uri}
}

Because admincp is an actual directory.

rewrite /admincp {
to index.php?routestring={uri}
}

section

gzip # Ha ha.

section

Requires third-party plugin https://caddyserver.com/docs/expires

#expires {

match .js$ 14d # 1209600 = 14 days

match .css$ 1y # 31536000 = 365 days - wow, seems a little long for CSS

match .(gif|jpg|jpeg|png|ttf|otf|woff|svg)$ 1m # 2592000 = 30 days

#}
tls {
dns cloudflare
}
}

The expire is in hash marks because the Cent OS 7 caddy does not come with the expire plugin. And i don’t like building anything unless i absolutely have too.

The images you posted make me think that perhaps login.php isn’t being served correctly and that’s the bottleneck.

The Caddyfile I wrote is based off the .htaccess file from back in 2017, has the configuration changed since then?

Can you post the current .htaccess file?

Try to format your configuration in code blocks using three backticks (```) instead of quoting it, which does terrible things to the formatting.

1 Like
	RewriteEngine On

	# In some cases where you have other mod_rewrite rules, you may need to remove the 
	# comment on the following RewriteBase line and change it to match your folder name. 
	# This resets the other mod_rewrite rules for just this directory
	# If your site was www.example.com/forum, the setting would be /forum/
	#RewriteBase /

	#To redirect users to the secure version of your site, uncomment the lines below 
	#RewriteCond %{HTTPS} !=on
	#RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

	# Send css calls directly to the correct file VBV-7807
	RewriteRule ^css.php$ core/css.php [NC,L]

	# Redirect old install path to core.
	RewriteRule ^install/ core/install/ [NC,L]

	# Main Redirect
	RewriteCond %{REQUEST_URI} !\.(gif|jpg|jpeg|png|css)$
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.*)$ index.php?routestring=$1 [L,QSA]

	# Because admincp is an actual directory.
	RewriteRule ^(admincp/)$ index.php?routestring=$1 [L,QSA]

</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
                          text/javascript \
                          application/x-javascript \
                          application/javascript \
                          application/json \
                          application/rss+xml \
                          application/vnd.ms-fontobject \
                          application/x-font-ttf \
                          application/xhtml+xml \
                          application/xml \
                          font/opentype \
                          image/svg+xml \
                          image/x-icon \
                          text/css \
                          text/html \
                          text/plain \
                          text/x-component \
                          text/xml
</IfModule>

<IfModule mod_expires.c>
	ExpiresActive On
	ExpiresByType application/x-javascript A1209600
	ExpiresByType text/javascript A1209600
	ExpiresByType application/javascript A1209600
	ExpiresByType text/css A31536000
	ExpiresByType image/x-icon A2592000
	ExpiresByType image/icon A2592000
	ExpiresByType application/x-ico A2592000
	ExpiresByType application/ico A2592000
	ExpiresByType image/gif A2592000
	ExpiresByType image/jpeg A1209600
	ExpiresByType image/jpg A1209600
	ExpiresByType image/png A1209600
	ExpiresByType application/x-shockwave-flash A1209600
	ExpiresByType font/ttf A2592000
	ExpiresByType font/otf A2592000
	ExpiresByType font/x-woff A2592000
	ExpiresByType image/svg+xml A2592000
	ExpiresByType font/truetype A2592000
	ExpiresByType font/opentype A2592000
	ExpiresByType application/x-font-woff A2592000
	ExpiresByType application/vnd.ms-fontobject A2592000
</IfModule>

<IfModule mod_headers.c>
    Header set Connection keep-alive
	<filesmatch "\.(ico|flv|gif|swf|eot|woff|otf|ttf|svg)$">
		Header set Cache-Control "max-age=2592000, public"
	</filesmatch>
	<filesmatch "\.(jpg|jpeg|png)$">
		Header set Cache-Control "max-age=1209600, public"
	</filesmatch>
	<filesmatch "\.(eot|woff|otf|ttf|svg)$">
		Header set Cache-Control "max-age=2592000, public"
	</filesmatch>
	# css and js should use private for proxy caching https://developers.google.com/speed/docs/best-practices/caching#LeverageProxyCaching
	<filesmatch "\.(css)$">
		Header set Cache-Control "max-age=31536000, public"
	</filesmatch>
	<filesmatch "\.(js)$">
		Header set Cache-Control "max-age=1209600, public"
	</filesmatch>
</IfModule>

#don't allow some files that shouldn't really be present to be directly accessed.
#note that attachements should never be directly accessed by the webserver because
#we have permissions on the that are checked in the PHP code.
<FilesMatch "(^#.*#|\.(bak|config|dist|inc|ini|log|gz|tar|zip|sh|sql|sw[op])|~)$">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

Thats the current .htaccess they give for 5.5.1

Hmm…

Does login.php actually exist in the web root?

1 Like

No it doesn’t. Login exists in root/core/login.php and the admincp exists in root/core/admincp/

Add this to your Caddyfile:

log / stdout "{common} /// {rewrite_uri}"

(change stdout for a path to a log file if you like instead)

Then run Caddy again, try to log in, and post the output.

I’m looking for confirmation of exactly how the rewrite executed when you attempt a login.

1 Like

Where should i look for the log file?

Wherever you decided to put it.

/var/log/caddy.log is a conventional suggestion.

If you used stdout - probably in journalctl if you started it back up as a service.

1 Like
Apr 14 19:55:07 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:07 -0500] "GET /admincp/index.php HTTP/1.1" 200 4012 /// index.php?routestring=/admincp/index.php
Apr 14 19:55:07 vultr.guest caddy[13902]: 172.68.58.38 - - [14/Apr/2019:19:55:07 -0500] "GET /core/cpstyles/global.css?v=551 HTTP/1.1" 200 1274 /// /core/cpstyles/global.css?v=551
Apr 14 19:55:09 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:09 -0500] "POST /login.php?do=login HTTP/1.1" 404 7738 /// index.php?routestring=/login.php?do=login
Apr 14 19:55:10 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:10 -0500] "GET /sprite.php?styleid=29&td=ltr&sprite=sprite_icons_general.svg&ts=1555261808 HTTP/1.1" 404 7738 /// index.php?routestring=/sprite.php?styleid=29&td=ltr&sprite=sprite_icons_general.svg&ts=1555261808
Apr 14 19:55:10 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:10 -0500] "POST /ajax/api/options/fetchValues HTTP/1.1" 200 50 /// index.php?routestring=/ajax/api/options/fetchValues
Apr 14 19:55:10 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:10 -0500] "POST /ajax/api/options/fetchValues HTTP/1.1" 200 50 /// index.php?routestring=/ajax/api/options/fetchValues
Apr 14 19:55:10 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:10 -0500] "POST /ajax/api/options/fetchValues HTTP/1.1" 200 50 /// index.php?routestring=/ajax/api/options/fetchValues
Apr 14 19:55:11 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:11 -0500] "GET /sprite.php?styleid=29&td=ltr&sprite=sprite_icons_general.svg&ts=1555261808 HTTP/1.1" 404 7738 /// index.php?routestring=/sprite.php?styleid=29&td=ltr&sprite=sprite_icons_general.svg&ts=1555261808
Apr 14 19:55:11 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:11 -0500] "POST /ajax/api/options/fetchValues HTTP/1.1" 200 50 /// index.php?routestring=/ajax/api/options/fetchValues

Thats the log

So, in this part, it rewrites to the index just fine…

Apr 14 19:55:07 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:07 -0500] "GET /admincp/index.php HTTP/1.1" 200 4012 /// index.php?routestring=/admincp/index.php

But in this part…

Apr 14 19:55:09 vultr.guest caddy[13902]: 108.162.216.139 - - [14/Apr/2019:19:55:09 -0500] "POST /login.php?do=login HTTP/1.1" 404 7738 /// index.php?routestring=/login.php?do=login

We get a 404 after rewriting to the index…

I have to wonder if the index PHP itself is generating the 404 here? If so, why?

I’m reluctant to advise modifying the rewrite to send login.php to /core/login.php without understanding why it’s structured that way or why the supplied .htaccess doesn’t do that. As far as I can tell, we’re replicating the .htaccess very faithfully right now.

Does vBulletin offer support? Can you query them as to why the login doesn’t work when it’s rewritten to index.php (like their own .htaccess appears to do)?

1 Like

As far as i know, they only support apache as the main approach to their software and nginx as a secondary since it became so popular, i’ve queried them before i posted here and their official response was that “We don’t have anyone with experience with caddy in our support team, maybe you can try to the forums” to which the forum’s don’t have anything either, so far anyway.

Normally if it were straightforward enough I’d look into hosting it myself and doing some rapid troubleshooting but it looks like there’s a hefty license fee to use vBulletin.

My strong recommendation at this point, given that their web server requirement seem a bit opaque and the support for Caddy nonexistent - just run it on Apache and reverse proxy to it from Caddy to get the best of both worlds (out of the box configuration/support + Caddy’s features).

1 Like

So how would i run apache, as i use caddy for more than one domain, i use caddy for right now 5 domains, and growing.

Configure Apache to serve your vBulletin site on port 8080 (or similar), then reverse proxy to http://localhost:8080 in your Caddyfile for the site.

1 Like

This works great, i can access the admin cp due to apache using the Htaccess file and caddy serves it up with SSL and PHP

Thank you for your help!

Oh and it’s going to be great for others to see this for support if they ever wanna host Vbulletin sites as well!

As well as my configs.

example.com {
    proxy / localhost:19999
}
caddy 
<VirtualHost *:8080>
    ServerAdmin Email Here
    ServerName Domain or Sub Domain
    DocumentRoot Document root where all your files are stored
    ErrorLog Logging Directory for Errors.
    CustomLog Logging Directory for access.combined files.
</VirtualHost> 
Apache2
2 Likes

So, apache works, but using caddy, it proxies to localhost:8080, and doesn’t seem to keep up with the fact that apache is hosted on 8080 and it doesn’t try to see the website that is hosted on 8080