dotCloud nginx.conf: how to get the "index index.php" directive to work? - dotcloud

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.

Related

Allow app to be loaded from a folder path in NGINX

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.

Nginx error: rewrite or internal redirection cycle while internally redirecting to "/index.md"

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;
}

Woocommerce REST API - Nginx - Error 404 Not Found

I'm trying to use the Woocommerce (v 3.5.4) Rest Api on my VPS (debian 9, Nginx).
Everything works well in my local machine (windows 10, XAMPP).
wpbop/ is the folder (var/www/wpbop/) where the wordpress files are stored.
The next basic URL in a browser should send the endpoints of the API (no need of athentication for this first step) :
http://my-public-ip/wpbop/wp-json/wc/v3
Or a curl in command line
curl http://127.0.0.1/wpbop/wp-json/wc/v3
in both cases, i get error 404 Not Found.
I can acces to the blog / admin blog without any problems ( http://my-public-ip/wpbop )
My permalinks are set on "Postname" in wordpress admin panel, this is recommanded by many people in same case.
EDIT - SOLUTION :
Since my Wordpress installation is in a sub-domain,
try_files $uri $uri/ /index.php$is_args$args;
can't find index.php. Just change this line by :
try_files $uri $uri/ /wpbop/index.php$is_args$args;
and it works !
Perhaps problem is coming from my Nginx conf file ?
server {
server_name localhost;
listen 80;
root /var/www;
location /wpbop {
index index.php;
access_log /var/log/nginx/blog.access.log;
error_log /var/log/nginx/blog.error.log;
try_files $uri $uri/ /index.php$is_args$args;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:7000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
}
I tried many things without any results, and I'm stuck for several days. Can someone help me ?
Thanks for reading me.
This case need a simple fix in the NGINX configuration file. This is related to the path of my wordpress installation.
Since my Wordpress installation is in a sub-domain,
try_files $uri $uri/ /index.php$is_args$args;
--> can't find index.php. Just change this line by :
try_files $uri $uri/ /wpbop/index.php$is_args$args;
when you get 404 code. try to access http://yoursite/?rest_route=/wp/v2/posts
Official documents https://developer.wordpress.org/rest-api/key-concepts
Move root /var/www/; by one level up (to server context). It is not being inherited.

Nginx config for single page app with HTML5 App Cache

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;
}

How to develop and deploy Catalyst fastcgi apps with nginx and custom URIs?

Probably it's not so relevant, but I'll start with my environment: Linux OS, Perl 5.10, Catalyst 5.80032, nginx 1.0.11.
For the sake of the question, let's suppose I'm using mydomain.com on port 80 as an access point for the app's web page. Also let's use /var/www/mydomain as the physical location of my Catalyst application. In this case the static content is located at /var/www/mydomain/MyApp/root/.
I start the application as a fastcgi server (from MyApp/script):
> ./myapp_fastcgi.pl -l /tmp/myapp.socket -n 2 -p /tmp/myapp.pid -d
I start the nginx server with the following config:
server {
listen 127.0.0.1:80;
server_name mydomain.com;
location / {
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass unix:/tmp/myapp.socket;
}
location /static {
root /var/www/mydomain/MyApp/root;
}
}
and everything seems to work fine when I access the app as http://mydomain.com/ or http://mydomain.com/products as another page (handled by MyApp::Controller::Products).
Now the challenge and the question: how should be nginx configured so it could serve applications' pages with an URI prefix (for example /some/prefix)?
In this case rootpage should be accessed as http://mydomain.com/some/prefix/ and the second one as http://mydomain.com/some/prefix/products.
The second part of the question is: how should be the application code modified in order to have valid URIs for redirects and all the pages? i.e. how $c->uri_for() and similar methods should be (re)written to have the same behavior for prefixed paths?
I have tried the dummy straightforward adjustment
location /some/prefix {
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass unix:/tmp/myapp.socket;
}
but of course it doesn't work this way. So, I'm not able to get responses even to manually typed in URLs before moving to Perl code and play with redirects and URLs generation.
There is in nginx such directive like alias. It works this way:
If you have a url with value of http://my.domain.com/some/prefix/blabla.file and use alias directive with location directive as follows:
location /some/prefix {
alias /var/www/mydomain/MyApp/root;
}
The resulting url will be /var/www/mydomain/MyApp/blabla.file. Why? Because alias directive in location block use it's value (alias value) as temporary root for serving files and request and trim from request part matched in location so when request was /some/prefix/blabla.file here it will be only /blabla.file and when you add this to alias value then you will get what you want (if I understood you well).
According to our discusion belove in comments I can propose two things.
First, in nginx you can add such location block:
location ~ ^/some/prefix(.*)$ {
rewrite ^/some/prefix(.*)$ $1;
}
This directive will delete /some/prefix from /some/prefix/products and leave you only with /products. Next change your location block to looks like following one:
location / {
include fastcgi_params;
# Here you provide for your Catalys real uri which was orignally provided by user
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass unix:/tmp/myapp.socket;
}
So you set param REQUEST_URI for your Catalys to has value of user request without any modifications. In nginx are to variables $request_uri and $uri. Value of this first one never changes and of the second one changes everytime when it's, for example, rewrited by rewrite directive. Moreover this will work because location ~ has higher priority than just location / so request url will be always first trimed to only this what comes after /some/prefix pattern.
Will it be helpfull now?