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 · 16 comments

Comments

Projects
None yet
4 participants
@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

This comment has been minimized.

Show comment
Hide comment
@LeoColomb

LeoColomb Nov 10, 2014

Member

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"
)
Member

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

This comment has been minimized.

Show comment
Hide comment
@heubergen

heubergen 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 :)

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

This comment has been minimized.

Show comment
Hide comment
@LeoColomb

LeoColomb Nov 10, 2014

Member

(EOL)

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

line: 37

Could you post this line?

Member

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

This comment has been minimized.

Show comment
Hide comment
@heubergen

heubergen 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?

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

This comment has been minimized.

Show comment
Hide comment
@LeoColomb

LeoColomb Nov 10, 2014

Member

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

Member

LeoColomb commented Nov 10, 2014

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

@heubergen

This comment has been minimized.

Show comment
Hide comment
@heubergen

heubergen 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.

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

This comment has been minimized.

Show comment
Hide comment
@LeoColomb

LeoColomb Nov 10, 2014

Member

Hmm... Try:

Member

LeoColomb commented Nov 10, 2014

Hmm... Try:

@heubergen

This comment has been minimized.

Show comment
Hide comment
@heubergen

heubergen 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.

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

This comment has been minimized.

Show comment
Hide comment
@LeoColomb

LeoColomb Nov 11, 2014

Member

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.
Member

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

This comment has been minimized.

Show comment
Hide comment
@heubergen

heubergen 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?

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

This comment has been minimized.

Show comment
Hide comment
@LeoColomb

LeoColomb Nov 12, 2014

Member

Have you enable FastCGI?

$ sudo lighty-enable-mod fastcgi
$ sudo lighty-enable-mod fastcgi-php
Member

LeoColomb commented Nov 12, 2014

Have you enable FastCGI?

$ sudo lighty-enable-mod fastcgi
$ sudo lighty-enable-mod fastcgi-php
@heubergen

This comment has been minimized.

Show comment
Hide comment
@heubergen

heubergen 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 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 from Add lighttpd rules (have solution) to Add lighttpd rules Nov 14, 2014

@heubergen

This comment has been minimized.

Show comment
Hide comment
@heubergen

heubergen 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 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

This comment has been minimized.

Show comment
Hide comment
@LeoColomb

LeoColomb Nov 28, 2014

Member

@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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@gsdefender

gsdefender Apr 24, 2016

Hi,
I have found that the rewrite rules found here work.
As I have enabled the dash support plugin, I had to add the dash in 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"
) 

gsdefender commented Apr 24, 2016

Hi,
I have found that the rewrite rules found here work.
As I have enabled the dash support plugin, I had to add the dash in 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

This comment has been minimized.

Show comment
Hide comment
@okoestner

okoestner 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?

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment