Directory listing: 403 Forbidden nginx - nginx

Hello I started using nginx, set up the nginx.conf to my project folder C: / Projects.
I used (AutoIndex: on) to have a list of directories, but does not work
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name localhost;
root C:\Project ;
index index.html index.htm index.php;
location / {
autoindex on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

Move your autoindex on; outside your location block
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name localhost;
root C:\Project ;
index index.html index.htm index.php;
# moved here
autoindex on;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

If you have one of the index files present inside your root directory (or any subdirectory under C:\Project for that matter), the index page will be shown rather than the index of contents.
You may also want to check the permissions on all content under your root; they need to be readable by the user running your Nginx process.
Could be a number of different things; you'll need to clarify your questions in future with what you've tried and haven't tried.

Related

Block specific file out of static directory with nginx

I have a statically served React application with Nginx.
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 3000;
server_name localhost;
root /usr/share/nginx/html;
location ^~ /static/ {
root /usr/share/nginx/html/;
}
location / {
try_files $uri /index.html;
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
During build (with Vite) we produce source maps which are served in development.
For specific environments (stage.* and app.* but not dev.*) I would like to not serve the source maps.
I have no option to not build source maps for these environments in the first place, because we migrate entire builds between environments.
I want to use Nginx to not serve *.map files out of /static for these environments.
How would I do that?

Remove query string from nginx

I'm having some trouble with an nginx.conf. I have a front end application which appends this code to the URL after a user logs in. I'm trying to have nginx remove this ?code=randomcode. I tried writing an nginx rewrite rule, but it is conflicting with another rule I have in place it seems. Below is the nginx.conf file:
worker_processes 1;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri$args $uri$args/ /index.html;
location /app1 {
try_files $uri$args $uri$args/ /index.html;
rewrite ^/app1(/.*) $1;
break;
}
location /app1/ {
set $args '';
rewrite ^/app1/(.*)$ /app1/$1 permanent;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
I am new to writing directives for nginx config files, so the logic may not make sense, but basically with the last rewrite rule written furthest down is causing all the JS files to report 404 (Not Found).
Any advice would be appreciated.

https to http for an old program

(sorry, bad english)
I have an old software, that call webpages.
But it cannot call https-pages, only http.
My nginx.conf for nginx:
worker_processes 1;
events {worker_connections 1024;}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#------------------
# from me:
server {
server_name localhost; listen 30001;
set $x https://www.example1.com/downloads;
location / { proxy_pass $x; }
}
server {
server_name localhost; listen 30002;
set $x https://www.example2.com/news;
location / { proxy_pass $x; }
}
...
#------------------
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {root html;}
}
}
Then in the software I can use:
http://localhost:30001 -> calls https://www.example1.com/downloads
http://localhost:30002 -> calls https://www.example2.com/news
Disadvantage:
I must write a server{}-Block for EVERY https-webpage into the nginx.conf.
Is ther a way to do https->http for ALL https-webpages?
Thank you very much for any help.

Nginx server not available to the public

I thought this Nginx setup was supposed to be easy :( I can get my index.html to load on localhost only but when I try to access the site by my domain name it doesn't work, or even if I try the server IP address externally it doesn't resolve :( What am I doing wrong? The is on Windows. Here is my conf;
#user nobody;
worker_processes auto;
events {
worker_connections 2048;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 5;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
root C:/xampp/htdocs;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
the issue was that I didn't enable Nginx in the Windows Firewall. Working now.

hls is not allowed here

this is my configuration and I'm getting an error:
'hls' is not allowed here
http {
access_log logs/rtmp_access.log;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location /hls {
hls;
hls_fragment 5s;
hls_buffers 10 10m;
hls_mp4_buffer_size 1m;
hls_mp4_max_buffer_size 5m;
root /run/shm;
}
#run/shm/hls/index.m3u8
# rtmp stat
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# you can move stat.xsl to a different location
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
so where do I suppose to put hls? I want to use http address and m3u8 file for show some video files on jwplayer
Are you using NGINX Plus or the third party module, nginx-rtmp-module, for this functionality? Note that HLS support is not otherwise supported.
If you're using the third-party module reference the nginx.conf example in the documentation.
(Disclaimer: I am affiliated with NGINX, Inc - the company that develops NGINX and NGINX Plus).

Resources