I need to modify the nginx config file (/etc/nginx/app.d/server.webstation-vhost.conf) to add one line, which is for Laravel routing work correctly.
location / { try_files $uri $uri/ /index.php?$query_string; }
The problem is /etc/nginx/app.d/server.webstation-vhost.conf will ALWAYS OVERWITTEN once reboot the NAS,
Does anybody having experience how to hand this problem.
Many Thanks !
Not sure if you figured this out, but if you haven't, under that vhost conf file (/etc/nginx/app.d/server.webstation-vhost.conf), look for something like:
include /usr/local/etc/nginx/conf.d/f2f0a62b-74d6-4c34-a745-d0156f13c9d6/user.conf*;
Instead of f2f0a62b-74d6-4c34-a745-d0156f13c9d6 you should see another unique id for your nginx app, create/edit the mentioned user.conf file (without asterisk) with the contents you need, in my case I created a file with the contents below:
location / {
try_files $uri $uri/ /index.html;
}
Then I had to restart nginx with the command sudo synoservice --restart nginx.
And it worked.
PS.: I believe it should work for any DSM v6.1 or later (maybe 6.0.x as well).
For research I used:
https://community.synology.com/enu/forum/1/post/122043
https://community.synology.com/enu/forum/1/post/120538
Related
I'm trying to configure my Nginx conf file but it doesnt want to work ...
I want to serve some pdf files.
When you write the url "127.0.0.1/abcFile.pdf" Nginx should serve you the file which is located here : "/a/b/c/abcFile.pdf"
I can have multiple folders. Each time first 3 letters of the file name are the folders names.
So i'm trying this :
location ~* "\.(\w{1})(\w{1})(\w{1})(\w*.pdf)$" {
try_files $uri $uri/ /$1/$2/$3/$1$2$3$4 ;
}
But I only got an error 500... I can't figure out what i'm missing here.
This kind of code work with rewrite:
rewrite "(\w{1})(\w{1})(\w{1})(\w*.pdf)" $1/$2/$3/$1$2$3$4 permanent;
But here i'v an issue too : Too many redirect. If I remove the "permanent" it doesn't work anymore.
If you have any suggestion :) Thanks a lot !
Switching from Apache to NGINX here :)
So I have Site A which sits on the root directory http://test.fake.com/ and works fine. I also have another Wordpress Site (B) where the root is http://test.fake.com/b/
All the front end pages for B load scripts and css like http://test.fake.com/test.fake.com/b/ which of course is incorrect. When I try to goto the Admin like http://test.fake.com/wp-admin/ I receive No input file specified. as the only output, also the URL changes to http://test.fake.com/test.fake.com/b/wp-login.php.
Here is a snippet of my NGINX config where I think the problem lies, please let me know if you need more info and be gentle on a NGINX n00b :P
location /b {
try_files $uri $uri/ /b/index.php$args;
}
location / {
# Set try_files according WP architecture
try_files $uri $uri/ /index.php$args;
}
Here is a snippet of B's wp-config file where I am setting the URLs
define('WP_HOME','http://test.fake.com/b');
define('WP_SITEURL','http:/test.fake.com/b');
I have no idea where the error lies :(
Thank you for viewing!
I have a cachebreaker that produces css filenames as this one: /css/vendor.min.333311133.css.
I want nginx to answer request with a previous version with the latest.
Note that I will only have one version of that file in the directory... so I'm thinking of a rule like the following, but it's not working:
location ~* /css\/vendor\.min\.(.*)\.css {
try_files $uri ~* /css\/vendor\.(.*)\.css =404;
}
Does anybody knows if nginx support dynamic names in try_files? Or should I use another directive? Any ideas?
If your build process is able to do this, just put the file there without the cachebreaker part and do this:
location ~* /css\/vendor\.min\.(.*)\.css {
try_files /css/vendor.min.css =404;
}
In theory you can use a regex capture inside the location, but since the old version number would be in there, it would not help.
I have a very simple case of serving static files via nginx yet I can't figure it out.
I want all URLs beginning with /static/ to serve static files from directory /foo/bar/dir1 and if the file isn't there, serve from /foo/bar/dir2, if not there, return 404.
So for example when handling URL /static/some/file.png I want nginx to first try
/foo/bar/dir1/some/file.png
and then
/foo/bar/dir2/some/file.png
I know I should probably use something like this
location /static/ {
try_files .... something .....
}
but the documentation on try_files is very unclear to me. I tried a lot of combinations but nothing seems to work. Multiple alias directives would do the job but it won't work. I think the solution must be very simple but I cant get it right. It's kind of hard to debug how nginx resolves all these locations and files...
You can customize the root (make sure to update the try_files after). And also make sure there is no root directive in location /
location ~* ^/static/(.+)$ {
root /;
try_files /foo/bar/dir1/some/$1 /foo/bar/dir2/some/$1 =404;
}
Edit: Removed the need of the static folder.
When I try to use laravel PHP framework, I try to place it in a dir called /home/usr/proj/laravel, but as we know that the public html of laravel is settled in /home/usr/proj/laravel/public, thus my problem is how to make the setting of nginx such that when I access by mysite.com/laravel/ or mysite.com/laravel, we in fact redirected to the location laravel/public/index.php.
Also, it seems that there is a rule of nignx which is suggested by the official of laravel, to make the url looks pretty
location / {
try_files $uri $uri/ /index.php?$query_string;
}
How can I use this in my case?
UPDATE
It seems the following code works for me (but give me error NotFoundHttpException in RouteCollection.php line 145:, maybe caused by my router setting)
location /laravel{
root /home/usr/proj/laravel/public;
index index.php index.html;
try_files $uri $uri/ /laravel/public/index.php?$query_string;
}
Regarding your Update, I think that you should keep your original try_files syntax:
try_files $uri $uri/ /index.php?$query_string;
since the location is set to /laravel and the root is in the public folder. The way it is currently written ends up looking for file /home/usr/proj/laravel/public/public/index.php in the disk.
You should also check to configure your application URL so that it contains the /location part of the URL. I am not quite sure about how Laravel 5 is configured since my experience is with Laravel 4.