Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lighttpd rules #1809

Open
heubergen opened this issue Nov 10, 2014 · 22 comments
Open

Add lighttpd rules #1809

heubergen opened this issue Nov 10, 2014 · 22 comments
Labels

Comments

@heubergen
Copy link

@heubergen heubergen commented Nov 10, 2014

Hi Devs

Maybe you will add the follow informations to your wiki:
To run YOURLS with lighttpd you have to add the follow lines to your lighttpd.conf:
# Rewrite rules for YOURLS
url.redirect = (
"^/([0-9A-Za-z]+)?$" => "/yourls-go.php?id=$1",
"^/([0-9A-Za-z]+)?\+$" => "/yourls-infos.php?id=$1" )

@LeoColomb
Copy link
Member

@LeoColomb LeoColomb commented Nov 10, 2014

Could you test these lines instead:

server.document-root = "/path/to/app"
url.rewrite-once = (
    # configure some static files
    "^/assets/.+" => "$0",
    "^/favicon\.ico$" => "$0",

    "^(/[^\?]*)(\?.*)?" => "/yourls-loader.php$1$2"
)
@heubergen
Copy link
Author

@heubergen heubergen commented Nov 10, 2014

That is my big problem with configs like that, I become always a error:
2014-11-10 21:44:09: (configfile.c.951) source: /etc/lighttpd/lighttpd.conf line: 37 pos: 17 parser failed somehow near here: (EOL)

FYI: server.document-root = "/var/www/url.MYDOMAIN.me/"

And thats the reason why I write something new :)

@LeoColomb
Copy link
Member

@LeoColomb LeoColomb commented Nov 10, 2014

(EOL)

Be careful of this: be sure to save the file with LF line ending.

line: 37

Could you post this line?

@heubergen
Copy link
Author

@heubergen heubergen commented Nov 10, 2014

Here is my complete file:

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
        "mod_rewrite",
    "mod_fastcgi",
)

server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

fastcgi.server = ( ".php" => (( 
                    "bin-path" => "/usr/bin/php-cgi",
                    "socket" => "/tmp/php.sock" 
                )))
server.document-root = "/var/www/url.***.me/"
url.rewrite-once = (
    # configure some static files
    "^/assets/.+" => "$0",
    "^/favicon\.ico$" => "$0",

    "^(/[^\?]*)(\?.*)?" => "/yourls-loader.php$1$2"
)

Line 36 (The error show now Duplicate config variable in conditional 0 global: server.document-root 2014-11-10 22:12:10: (configfile.c.951) source: /etc/lighttpd/lighttpd.conf line: 36 pos: 17 parser failed somehow near here: (EOL)) is:
url.rewrite-once = (

When I delete the Duplicate config variable in conditional 0 global: server.document-root line I can restart the service successfully, but I can of course not accessing to YOURLS.

But what do you mean with LF?

@LeoColomb
Copy link
Member

@LeoColomb LeoColomb commented Nov 10, 2014

What is your IDE? (Notepad++ / Visual Studio / Sublime Text / Atom / ...)

@heubergen
Copy link
Author

@heubergen heubergen commented Nov 10, 2014

I work on the command line :)
I use nano.

I'm not a developer and so I don't use a IDE.

@LeoColomb
Copy link
Member

@LeoColomb LeoColomb commented Nov 10, 2014

Hmm... Try:

@heubergen
Copy link
Author

@heubergen heubergen commented Nov 11, 2014

Thanks for you work, but you also declarine two server.document-root and obviously that will not work.

With the follow code it works for me AND it will effect only the right subdomain and not the other to (like my code above):

# Rewrite rules for YOURLS
$HTTP["url"] =~ "/url.***.me/" {
url.redirect = (
"^/([0-9A-Za-z]+)?$" => "/yourls-go.php?id=$1",
"^/([0-9A-Za-z]+)?\+$" => "/yourls-infos.php?id=$1" )
}

@LeoColomb If there's okay please write it in the wiki or comment if you find something that is wrong.

@LeoColomb
Copy link
Member

@LeoColomb LeoColomb commented Nov 11, 2014

In fact I dislike your proposal:

  • url.redirect is for redirection, here we want a rewrite.
  • /yourls-go.php?id=$1: this way is very old and it's the job of yourls-loader.php to use this file. In this way some YOURLS features are broken.
@heubergen
Copy link
Author

@heubergen heubergen commented Nov 11, 2014

My problem with this code:

$HTTP["url"] =~ "/url.heubergen.me/" {
url.rewrite-once = (
    # configure some static files
    "^/assets/.+" => "$0",
    "^/favicon\.ico$" => "$0",

    "^(/[^\?]*)(\?.*)?" => "/yourls-loader.php$1$2"
)
}

is that I become a 404 - Not found
You can see that with this example url: http://url.heubergen.me/test
I can restart the lighttpd server without any error.

What my question is:
What is the right url that forward me to my destination?

@LeoColomb
Copy link
Member

@LeoColomb LeoColomb commented Nov 12, 2014

Have you enable FastCGI?

$ sudo lighty-enable-mod fastcgi
$ sudo lighty-enable-mod fastcgi-php
@heubergen
Copy link
Author

@heubergen heubergen commented Nov 12, 2014

fastcgi was already enabled, but I have to enable fastcgi-php and so edit my code:

...
# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

# Rewrite rules for YOURLS
 $HTTP["url"] =~ "/url.heubergen.me/" {
 url.rewrite-once = (
    # configure some static files
    "^/assets/.+" => "$0",
    "^/favicon\.ico$" => "$0",

    "^(/[^\?]*)(\?.*)?" => "/yourls-loader.php$1$2"
)
}

But I become still the error 404 by visit the url http://url.heubergen.me/test
Restart was without any error :(

@heubergen heubergen changed the title Add lighttpd rules (have solution) Add lighttpd rules Nov 14, 2014
@heubergen
Copy link
Author

@heubergen heubergen commented Nov 28, 2014

I just want to say that I use the follow config now:

# Rewrite rules for YOURLS
$HTTP["host"] =~ "url.heubergen.me" {
url.redirect = (
"^/([0-9A-Za-z]+)?$" => "/yourls-go.php?id=$1",
"^/([0-9A-Za-z]+)?\+$" => "/yourls-infos.php?id=$1" )
}

Only to use with lighttpd 1.4.35 or newer.

Thanks for your help @LeoColomb, I will close this issue now.

@heubergen heubergen closed this Nov 28, 2014
@LeoColomb
Copy link
Member

@LeoColomb LeoColomb commented Nov 28, 2014

@heubergen Thanks a lot for your feedback and your tests!

Nevertheless, I prefer to keep this issue opened because the solution isn't adequate to the current YOURLS behavior.

@LeoColomb LeoColomb reopened this Nov 28, 2014
@gsdefender
Copy link

@gsdefender gsdefender commented Apr 24, 2016

Hi,
I have found that the rewrite rules found here work OK.
As I have enabled the dash support plugin, I had to add the dash to the set of matching characters.

url.rewrite-once = (
    "^/([0-9A-Za-z-]+)?$" => "/yourls-go.php?id=$1",
    "^/([0-9A-Za-z-]+)?\+$" => "/yourls-infos.php?id=$1"
) 
@okoestner
Copy link

@okoestner okoestner commented May 17, 2018

I have to re-open that... I am running yourls 1.7.2 and the latest lighhtpd.
My vhost section looks like this:

$HTTP["host"] == "go.server.com" {
server.document-root = "/var/www/go.server.com"
url.redirect = (
"^/([0-9A-Za-z]+)?$" => "/yourls-go.php?id=$1",
"^/([0-9A-Za-z]+)?+$" => "/yourls-infos.php?id=$1"
)
}

Unfortunately all other vhost will also be redirected to "/yours...". Any idea?

@jaquer
Copy link

@jaquer jaquer commented Jan 30, 2019

@okoestner: I know your request is old, but I believe it's because you are using redirect instead of rewrite.

Back to the original issue, I wanted to keep the functionality as close to the Apache one, and so far this seems to work for me:

url.rewrite-if-not-file += (
  "^/$" => "$0",
  "^/admin/.*$" => "$0",
  "^/.*$" => "/yourls-loader.php"
)

The if-not-file takes care of anything under the css, images and js directories, the ^/$ entry stops a redirect loop, ^/admin/.*$ lets anything under admin pass untouched, and finally ^/.*$ duplicates the behavior of the official .htaccess file, as far as I can tell. It even handles the /robots.txt and /favicon.ico special requests properly.

I'm using lighttpd-1.4.49. Hope it helps somebody out there.

@okoestner
Copy link

@okoestner okoestner commented Oct 1, 2020

One Covid pandemy later...
Sorry, since the last answer did not solve my issue I postponed that to later. And later is now ;)

The base URL (like go.server.com) works. Even the /admin URL works.
But if I try to redirect with sth. like "go.server.com/fun" which was successfully written to the database I will not be redirected successfully.
Instead I can see the following error message in the log file:

2020-10-01 23:11:17: (mod_fastcgi.c.2543) FastCGI-stderr: PHP message: PHP Fatal error: Uncaught RuntimeException: The gmp or bcmath extension must be installed to read this database. in /mnt/nas/maschine/www/go.server.com/includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php:295

Any idea?

@dgw
Copy link
Member

@dgw dgw commented Oct 1, 2020

The error message tells you what's missing. Install either gmp or bcmath PHP extension.

@okoestner
Copy link

@okoestner okoestner commented Oct 1, 2020

The error message tells you what's missing. Install either gmp or bcmath PHP extension.

But how? How do I determine what is missing? And how can I install it?

@dgw
Copy link
Member

@dgw dgw commented Oct 1, 2020

Both of those extensions are missing. You need at least one of them. How to install depends on your platform/OS, how PHP itself was installed, etc.

@okoestner
Copy link

@okoestner okoestner commented Oct 3, 2020

Thanks a lot, "dgw".
I installed both needed packages and everything works fine, now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.