I have an Angular application deployed in Nginx in /usr/local/etc/nginx/html location.
The app is working fine if I go to http://localhost:8000/#/search
I want to load the application as http://localhost:8000/lib/<company>/app/#/search as the lib/<company>/app portion is essential to get the company name from the URL.
I tried setting alias for /lib/(.*?)/app location in nginx.conf, which gives 404 for the path.
listen 8000;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/local/etc/nginx/html;
index index.html index.htm;
}
location /lib/(.*?)/app {
alias /usr/local/etc/nginx/html;
}
is there a way I can load the app and preserve the full URL in the browser?
Thanks.
Related
What I want is to restrict access to files for unauthorized user.
PocketBase documentation says I can retrieve the file URL and access files through it. The example URL for a file would be like this:
http://127.0.0.1:8090/api/files/example/kfzjt5oy8r34hvn/test_52iWbGinWd.png
I can prevent unauthorized users to get this URL, but authorized users can share URL with other one.
Any ideas?
I found a good way to secure files with nginx, by adding an extra location for my PocketBase server block and using an extra backend with one endpoint.
So, my nginx looks like this:
server {
listen 80;
server_name example.com;
location /api/files {
proxy_intercept_errors on;
error_page 404 = #fallback;
proxy_pass http://127.0.0.1:5000;
}
location / {
proxy_pass http://127.0.0.1:8090;
}
location #fallback {
proxy_pass http://127.0.0.1:8090;
}
}
Where my expressjs backend working on port :5000 checks JWT and responds with 404 if it is valid. Nginx will redirect to :8090 (PocketBase) if 404 returned on :5000.
I am trying to serve a vue app that has an index.md file as the root file. here is my nginx config:
server {
listen 7072;
listen [::]:7072;
root /home/dave/web/dist;
index index.md index.htm index.html index.php;
server_name 0.0.0.0:7072;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /home/dave/web/dist;
try_files $uri /index.md;
}
I tried to configure nginx as image server as below
create myapp.conf and put it at /etc/nginx/conf.d
server {
listen 80;
listen [::]:80;
#here you could also use subdomain
server_name image.mydomain.com ;
#here you could also use context,e.g. location /<context>
location / {
root /myapp/imageServer/;
autoindex on;
}
}
The file exists at /myapp/imageServer/card/3cdad37c5a394567b53283321f6af9e9.png
But when i browse this file via https://image.mydomain.com/card/3cdad37c5a394567b53283321f6af9e9.png. I got 403 forbidden from nginx. There is any mistake of my nginx config?
i found the reason
go to /etc/nginx/nginx.conf
edit line as below
#user www-data;
user root;
I'm trying to build a single page app that utilizes HTML5 App Cache, which will cache a whole new version of the app for every distinct URL, thus I must redirect everyone to / and have my app route them afterward (this is the solution used on devdocs.io).
Here's my nginx config. I want all requests to send a file if it exists, redirect to my API at /auth and /api, and redirect all other requests to index.html. Why is the following configuration causing my browser to say that there is a redirect loop? If the user hits location block #2 and his route doesn't match a static file, he's sent to location block #3, which will redirect him to "/" which should hit location block #1 and serve index.html, correct? What is causing the redirect loop here? Is there a better way to accomplish this?
root /files/whatever/public;
index index.html;
# If the location is exactly "/", send index.html.
location = / {
try_files $uri /index.html;
}
location / {
try_files $uri #redirectToIndex;
}
# Set the cookie of the initialPath and redirect to "/".
location #redirectToIndex {
add_header Set-Cookie "initialPath=$request_uri; path=/";
return 302 $scheme://$host/;
}
# Proxy requests to "/auth" and "/api" to the server.
location ~* (^\/auth)|(^\/api) {
proxy_pass http://application_upstream;
proxy_redirect off;
}
That loop message suggests that /files/whatever/public/index.html doesn't exist, so the try_files in location / doesn't find $uri when it's equal to /index.html, so the try_files always internally redirects those requests to the # location which does the external redirect.
Unless you have a more complicated setup than you've outlined, I don't think you need to do so much. You shouldn't need external redirects (or even internal redirects) or server-side cookie sending for a one-file js app. The regex match for app and api wasn't quite right, either.
root /files/whatever/public;
index index.html;
location / {
try_files $uri /index.html =404;
}
# Proxy requests to "/auth" and "/api" to the server.
location ~ ^/(auth|api) {
proxy_pass http://application_upstream;
proxy_redirect off;
}
I got auth to work by "pushing" an nginx.conf file in the application directory, so I know the file works, but /app will not trigger /app/php.index. I can't get nginx working on my vista laptop with php and I can't edit the /etc/nginx/nginx.conf in the dotCloud instance as dotCloud makes life difficult by not giving root.
(Note that the .htpasswd is relative to the ngnix.conf file location, nice).
server {
location / {
index index.php;
}
location /admin {
auth_basic "enter password";
auth_basic_user_file .htpasswd;
index index.php;
}
}
You may need an nginx directive to map requests to your dynamic content. This controller can can then route them appropriately.
try_files $uri $uri/ /index.php;
For an example project, see the CakePHP tutorial.