nginx 1.6.2 [Windows] won't find protected directory - html

as the headline said, my nginx isn't able to find .htpasswd-protected directories. Here are my settings, my .conf and the locations of the relevant files:
NOTE: due to my brothers wish, the nginx runs on a win8.1x32 virtual machine
I created a .htaccess file in my root/xx directory looking like this:
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /b/.htpasswd
AuthGroupFile /dev/null
require valid-user
And I created a .htpasswd file inside the shown directory.
After that I modified my .conf in the conf-folder like this:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ^~ /b/ {
auth_basic "Restricted Area";
auth_basic_user_file b/htpasswd;
}
}
I deleted the comment-lines from the auto-generated file only here, in the original, they are still existent - thought this might clear your sight on the file.
Now, here comes the problem: the file which I am aiming for is called int.html and can be found in /b/int.html (stylesheets and scriptfiles included), but every time i want to get to this file, the browser asks my to type in password and username - as I wanted it - but then the browser shows a 404-error, which means, he couldn't find the named file. (I made sure everything is spelled correct in the directories and tried this in several browsers on different devices). I don't know why. (I already tried to set the int.html as index in the config like this:
location ^~ /b/ {
auth_basic "Restricted Area";
auth_basic_user_file b/htpasswd;
}
But it still doesn't work. - Ideas, anyone?
Greetz Dyarn

Related

NGINX can not find Phpmyadmin Error 404 with Code-server

Hello guys I have a VPS with Ubuntu 20.04.
I have code-server installed and it works properly.
I also have Phpmy admin installed and mariadb, but when i go to my.ip.adress/phpmyadmin i get an 404 error.
I think the problems is that code-server tries to resolve the path or something like this.
My configuration looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name 178.254.34.3;
location / {
try_files $uri $uri/ =404;
}
location /phpmyadmin {
root /usr/share/phpmyadmin;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
index index.php index.html index.htm index.nginx-debian.html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Does someone can help me to solve this problem ?
I tried almost everything i could find on the web and it didnt solved the problem.
So I found the problem and it was very obvius at the end. When i first installed code-server i had to create a specifig configuration. so first of all my server was never using the default configuration i posted here. I changed a few things and now it works. At least I am able to see the login page and the info.php file i created. Thanks for your help.

Nginx server does not load css files from skeleton framework

Hey there,
I'm new when dealing with NIGNX servers and Linux. My HTML file is displayed but my server does not load the CSS files.
The only thing I found was this line
include /etc/nginx/mime.types;
which I include in the http block.
After that I reload my config with sudo nginx -s reload. To be sure I also executed sudo nginx -s stop and sudo nginx.
This is my whole config:
http {
include /etc/nginx/mime.types;
server {
location / {
root /data/www;
}
location ~ \.(gif|jpg|png)$ {
root /data/www/images;
}
}
}
events {}
My skeleton files are located in /data/www. In this directory there is another CSS folder.
Thank you in advance.
First of all, you're going to need to tell NGINX to have your static files to obtain a TTL (time to live) via expire headers. Locate this in your NGINX configuration file, if it isn't there. Create a new directive with location
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 1s;
}
After this go ahead and purge your files from the server and force it to serve new files.
Set sendfile off in nginx.conf
Set expires 1s in mysite.conf
Explicitly set Cache-Control header: add_header Cache-Control no-cache;
Of course, before doing anything above. If it doesn't require drastic measure, try manually deleting everything in the cache folder: /var/cache/nginx
If that doesn't help then proceed with everything listed here!
After you've successfully purged your server from serving static files. Add this to your NGINX server block to achieve optimization.
gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/x-javascript text/xml text/css application/xml;
It's possible to set expire headers for files that don't change and are served regularly.
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}

How to serve images with nginx

I am completely new to nginx and I am asked to find a way to serve Map Tiles that are separated according to the zoom levels. The image file structure is like ~/data/images/7/65/70.png where 7 is the zoom level, 65 and 70 are the lon-lat values. The folder 65 contains many files such as 71.png, 72.png and etc.
I have installed Nginx properly and I can get Welcome to nginx message. I have followed the instructions in http://nginx.org/en/docs/beginners_guide.html and created the /data/www and /data/images directories. I have placed index.html file under /data/www and tile images under /data/images. Then I modified the configuration file by adding following lines in http tags:
server {
location / {
root /data/www;
}
location /images/ {
root /data;
}
}
After reloading the config file and entering localhost on the browser I can neither get the index.html file nor see the images.
What I am trying to do is to display the image when I enter something as:
http://localhost/1.0.0/basemap/7/65/70.png
7: folder indicating 7th zoom level
65: folder indicating the latitude
70.png: file indicating the longitude (folder 65 includes many png files)
What am I missing?
Ok, let me explain something, you already have a localhost server, which is defined inside a file called default that is the file that causes the "Welcome to nginx" or something to appear, and I believe you can't create a new server with the same server_name, let's remove that and make your localhost serve only those images,
First we need to delete the default file from sites-enabled , it will still exist inside sites-available if you ever want to get it back. ( note that all files inside sites-enabled are simply symlinks from the files inside sites-available )
We create a new file inside sites-available and call it whatever you want, images-app for example
create the new server inside the images-app file, I'll assume that the root of the app is inside a folder called /data of course you will map that to your own server structure.
server {
server_name localhost;
root /data;
index index.html;
location / {
try_files $uri =404;
}
}
now we go to sites-enabled and enable this site we created inside sites-available
sudo ln -s /etc/nginx/sites-available/images-app /etc/nginx/sites-enabled/
make sure that all the nginx config are correct
sudo nginx -t
If nothing is wrong we can go ahead and reload nginx settings
sudo service nginx reload
For my case I just edited /etc/nginx/sites-enabled/default file.
I added following config:
location /images/ {
root /data;
}
and placed images under /data/images:
and url works: http://localhost/images/example.png
I use VS Code as SuperUser. (I know it is bad, but I accept risks)
It helps a lot with root access file editing:
I'm also new to nginx, Here is my solution that is similar with Mohammad AbuShady's answer :
delete sites-enabled/default
create the whatever.conf in /etc/nginx/conf.d/
The reason is:
sites-enabled/default has defined a server
that is listening on 80 rooting with /var/www/html
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
the nginx.conf file includes other conf files
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
pay attention on permission
the 1st edition of my.conf is root on /home/scotv/, but will get 403 Forbidden error, check the error.log:
2016/04/07 20:12:44 [error] 12466#0: *2 open() "/home/scotv/data/a" failed (13: Permission denied),
client: 127.0.0.1, server: , request: "GET /a HTTP/1.1", host: "localhost"

Nginx: can I use $server_name when specifying access log location?

I want to write a config file for an nginx virtual host that looks like this:
server {
listen 80;
server_name www.my-domain-name.com;
access_log /home/me/sites/$server_name/logs/access.log;
error_log /home/me/sites/$server_name/logs/error.log;
location /static {
alias /home/me/sites/$server_name/static;
}
location / {
proxy_pass http://localhost:8000;
}
}
Using $server_name seems to work find for the location /static, but it doesn't seem to work for the access_log and error_log -- am I doing something wrong? Or is this just not possible? Can I do it some other way?
[update] - this is the error message when trying to reload nginx:
nginx: [emerg] open() "/home/me/sites/$server_name/logs/error.log" failed (2: No such file or directory)
I wanted to do this too, but apparently by design nginx cannot expand variables in the error_log command, in case there are errors doing so and it cannot get a log filename to write them to.
Their suggestion is to use some program to generate your configuration files instead. You could use sed for this, to automatically search-and-replace your own variables and placing the output in the nginx configuration directory.

correct configuration for nginx to localhost?

I just installed nginx and php fastcgi about an hour ago, and after reading examples of a quick starting configuration, and the nginx documentation etc, I just cant get it to work.
No matter what I change or try, I always only get the "Welcome to Nginx!" screen on "localhost/..." - I cant even call a simple index.html
My config:
(the stuff in the comments is what I tried out)
// default nginx stuff (unchanged)
server {
#listen 80 default_server;
#listen 80 default;
listen 80;
#server_name localhost;
#server_name _;
#access_log /var/log/nginx/board.access_log;
#error_log /var/log/nginx/board.error_log;
#root /var/www/board;
#root /var/www/board/public/;
root /var/www/board/public;
#index index.html;
index index.html index.htm index.php;
}
If I understand it right, this should be the easiest setup, right? just define listen 80; and index index.html; but I just cant get it to work
The file /var/www/board/public/index.html exists and has content
Before I waste 2 more hours trying out something, can someone of you give it a quick watch and tell me what I'm doing wrong? Thanks.
Fundamentally you hadn't declare location which is what nginx uses to bind URL with resources.
server {
listen 80;
server_name localhost;
access_log logs/localhost.access.log main;
location / {
root /var/www/board/public;
index index.html index.htm index.php;
}
}