WordPress and YOURLS on one domain (Nginx) - yourls

I want to run both WordPress and YOURLS on one domain.
Since both need to handle URLs differently, they need different try_files directives. WordPress sits on the root of the domain (domain.tld), while YOURLS is being installed to the /go/ directory.
Despite the two location rules, I get 404s on any links generated by YOURLS (e.g. domain.tld/g/linkname, all are redirects to external URLs), though I can access the YOURLS admin backend.
As far as I read, declaring to location rules (one for /go/, and one for /) should suffice in order to let Nginx handle the direct and the /go/ URLS differently - is there something in wrong in my thinking?
I have added the following to the Nginx config:
location / {
try_files $uri $uri/ /index.php?$args;
}
location /go/ {
try_files $uri $uri/ /go/yourls-loader.php$is_args$args;
}
What am I missing?

Not sure if it will be of direct help to you or not.
I was trying to do a similar configuration using a subdirectory pointing to yourls docker
After many hits and trials, the following settings have worked for me. Maybe some part of it might be useful for someone.
location ~ (\/shorturl\/.*) {
if ( $uri ~ ^\/shorturl\/((admin|images|js|css)(\/?)(.*)|.*.(\.html|\.php)) ) {
rewrite /shorturl(/?)(.*) $1$2 break;
}
rewrite (\/shorturl\/.*) $1 break;
proxy_pass http://localhost:9091;
proxy_redirect / /shorturl/;
}
PS: I know if is evil and please add proxy headers as per your need!

Related

How do I install the intl extenuation for PHP on a Heroku hosted Laravel web application

I'm running a laravel app on heroku that is using Nova. I've gotten in deployed and everything seemed to work however I have a Product model that has a "price" field. The error message that I'm getting seems to suggest that there is an issue with the NumberFormatter::setAttribute() function in Symfony.
The error I receive when trying to render the main list of Product models is the following.
The Symfony\Component\Intl\NumberFormatter\NumberFormatter::setAttribute() method's argument $attr value 2 behavior is not implemented. The available attributes are: FRACTION_DIGITS, GROUPING_USED, ROUNDING_MODE. Please install the "into" extension for full localization capabilities"
Has anyone run into this error and what would solve it. I'm using niginx on heroku.
My Procfile is this.
web: vendor/bin/heroku-php-nginx -C nginx_app.conf /public
and my nginx_app.conf has this in it.
location / {
# try to serve file directly, fallback to rewrite
try_files $uri #rewriteapp;
}
location #rewriteapp {
# rewrite all to app.php
rewrite ^(.*)$ /index.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
try_files #heroku-fcgi #heroku-fcgi;
internal;
}
composer require ext-intl should do the trick to install the intl extension (which is available on Heroku, but as an optional extension), or you can manually add this to the require section of composer.json:
"ext-intl": "*",

Setting nginx expire headers only for fonts

In my nginx configuration, I have this location directive:
location /static/ {
alias /var/www/myproject/myproject/static/;
access_log off;
expires 30m;
break;
}
Now, I want to set the 'expires' to 1y only for files (within /static/) with extension .woff, woff2.
The problem is that the fonts files can be in many different subfolders of /var/www/myproject/myproject/static/
I have tried appending this other directive (after the other one)
location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
access_log off;
expires 1d;
break;
}
But the fonts files are throwing a 404 error.
Any help?
Many thanks!

laravel 5.3 returning notfoundexception when trying to load a woff / ttf file from public directory

trying to access
http://dev.myapp.org/caup_api/css/font-awesome/fonts/fontawesome-webfont.woff?v=4.7.0
return
NotFoundHttpException in RouteCollection.php line 161:
accessing
http://dev.myapp.org/caup_api/css/font-awesome/fonts/fontawesome-webfont.css?v=4.7.0
returns 404. 404 is expected, as the file is not a CSS file. but notfoundhttpexception is not
why is that and why cannot I load fonts via public folder?
lets make it clear:
the font file is there
not found http exception is only expected for proper routes, not for files in the public folder. It seems that .woff is not trying to reach a file in the public folder. Is it an nginx config problem?
actually have a subfolder installation of laravel
had to fix the following lines marked with ##, where caup_api is my subfolder
location ~ /caup_api {
## try_files /caup_api/$uri /caup_api/$uri/ /caup_api/index.php?q=$uri&$args;
try_files $uri $uri/ /caup_api/index.php?$query_string;
}

Nginx configuration to deny access to private Laravel folders

Every answer or tutorial about nginx configuration on Laravel has something like that:
location ~ \.php {
# fastcgi stuff ...
}
If the Laravel framework has a unique entry point (the public index.php), wouldn't it be this definition more accurate?
location ~ index\.php {
# fastcgi stuff ...
}
In a context where you have your app deployed on a subfolder, the first configuration it's allowing the access on every php private file, even if I have already defined a deny all rule over the private folder.
I'm wrong with anything?
There is another way to define a fully deny access over a folder?
If you want deny access to files in your private folder (e.g. /private) add this to your config for virtual host:
Case sensitive
location ~ ^/private/(.*)\.php$ {
deny all;
}
Case insensitive:
location ~* ^/private/(.*)\.php$ {
deny all;
}
This returns 403 all requests to /private/something.php, /private/something/something.php and so on. But requests to /private/something will work.

proper way to manage images and static files nginx

I'm a new coming to nginx service, I misunderstand how nginx manage the files to do show.
Let's say an example. In my web application I have statics file with this path:
---public
| -- js
| -- img
| -- css
For invoke this kind of static files it just need to digit the current url: www.mysite.com/js/some.js or www.mysite.com/img/myimg.jpg that's fine it will show up.
But now let's say I have a script on my php files that use a different url to get a image from public/img folder using example www.mywebsite.com/20/10/29/myimg.jpg
if I add this code to my configuration in nginx, it will get correctly all files to serve to my application giving of course a real path of the file
location ~* \.(jpe?g|gif|png|ico|css|js|html|htm|woff|svg|ttf)$ {
access_log off;
expires max;
}
Getting the previous example with the url that generate the image, if I use that block of code in nginx and i try to go:
www.mywebsite.com/20/10/29/myimg.jpg
The image will displayed correctly because i show it via php, but on the console log the image get a 404 because nginx go to search for the file with extension jpg on public/20/10/29/myimg.jpg even if the file is on the public/img folder it make sense.
My question is, some one can explain to me how nginx logic has been created for serve static files and files via dynamic url?
Proper way is to get rid of awful block location ~* (...) and use simple prefix locations.
location /img/ {
access_log off;
expires max;
}
location /js/ {
access_log off;
expires max;
}
location /css/ {
access_log off;
expires max;
}

Resources