Static not existing though being declared in nginx default config - nginx

I'm trying to get my static files accessible so that I can load them with Flask.
ex: https://example.com/static/render.css
I've included this in the https part of my site:
location /static/ {
autoindex on;
alias /root/site/static;
}
But it just returns a 403 always.
The directory is correct and all, I've also ran the chown -R /root/site/static/ command. Idk what's the issue.
Nginx is definitely doing something with the data though, as all other extensions just reply a badgateway.

I decided to just write my CSS inline.

Related

Nginx S3 proxy: Attempt to serve index.html on the first 404

I have a really simple setup, I just want nginx to act a webserver for S3.
Meaning that if it hits a folder instead of returning key not found from S3 I want it to return the index.html of that possible folder.
Chrome does this automatically, but I am using it for a Python Pip repo, which doesn't automatically try the index.html.
location / {
aws_sign;
proxy_pass http://[my bucket].s3.amazonaws.com;
}
All the answer that I've been able to find revolve around serving files instead, but that's not what I want. What I want is for nginx to retry the proxy with a different [url] namely [url]/index.html.

Nginx location and try_files in subdirectory

I'm trying to configure nginx vhost for application and stucked.
App is in directory /site/verb
At this moment app have this kind of links and it is working:
http://example.com/verb/lt.php?some_args=some_args&some_args?some_args
What I need? I need add another link for my clients like below:
http://example.com/v/lt.php?some_args=some_args&some_args?some_args
It is only change from /verb to /v but I want to handle both (for compatibility reasons) with all arguments after .php extension.
Is it possible in nginx config? (I want to avoid creating symlinks in directory).
I tried symlinks but it is not good solution.

Environment variable in Valet

I am using default installation of Valet (https://laravel.com/docs/5.4/valet).
I have small experience with nginx, therefore I can't locate where should I store envvars for Valet.
For apache it would be quite easy - /etc/apache2/envvars
As a temporary solution on PHP, index.php, I use putenv('APP_ENV=dev'); but I would like to do this globally without touching index file.
Thanks.
Since I find this post when I am looking for an answer, it will be easier for me if I leave a note for my self here.
Since I installed nginx using brew, nginx config is located in /usr/local/etc/nginx, and environment variables are already set in fastcgi_params file.
Append to file
/usr/local/etc/nginx/fastcgi_params
a new line, for example
fastcgi_param APP_ENV dev;
If you don't want to set this environment variable globally, it can be overwritten for each site config in ~/.valet/Nginx/site.dev between location ~ \.php$ { closure.

How to get nginx.conf include directive to ignore .bak files

How do I get the include directory for ngnix conf files to ignore *.bak?
I back up my configuration files, for example default -> default.bak. I want to include /etc/nginx/sites-enabled/default but not /etc/nginx/sites-enabled/default.bak in nginx.conf. How do I do this?
I would recommend changing default to default.conf or another extension if possible , then include can properly differentiate from config and bak.
http {
include /etc/nginx/sites-enabled/*.conf;
}

Applying NGINX location based on extension of default file.

I'm trying to create an alternate location in NGINX that will only fire for a specific file type. Specifically, I have NGINX acting as a proxy for a server that primarily serves PHP files. There are, however, a bunch of folders that also have ASPX files (more than 120), and I need to use a different configuration when serving them (different caching rules, different Modsecurity configuration, etc).
NGINX is successfully detecting the file type and applying the alternate location when the file name is specifically listed, but it's breaking when the ASPX file is the default file in the folder and the URL simply ends in a slash. When that happens, it's just applying the root location configuration. Is there a way to detect the extension of an index file and apply an alternate location, even when the name of the index file isn't specifically entered?
server {
listen 80;
server_name mysite.com;
# serves php files and everything else
location / {
#general settings applicable to most files
proxy_pass http://#backend;
}
#serves .Net files
location ~* \.(aspx|asmx) {
#slightly different settings applicable to .Net files
proxy_pass http://#backend;
}
}
If a folder has a file called "default.aspx" configured as it's index, the above configuration works perfectly if I enter the url as mysite.com/folder/default.aspx, but it applies only the base location if I enter it as mysite.com/folder, even though it is serving the exact same default.aspx file.
The only solution I've found is to alter the location directive to identify by the folder name instead of the file extension, but this doesn't scale well as there are more than 120 affected folders on the server and I'd end up with a huge conf file.
Is there any way to specify a location by file extension, when the file isn't specifically named in the URL? Can I test a folders index file to determine its extension before a location is applied?

Resources