Is there any way to allow an ip to access all paths and files on the server?
I mean really any path or file.
Because i have some problems with mono that it tells me that my file is forbidden
Yes you can do this, but it's really not recommended, especially if this is a live/production website. You simple have to set autoindex to all for the root path. Setup your list of addresses with geo and an if statement.
geo $allow_addresses {
default 0;
144.0.0.0/24 1;
}
server {
listen 80;
server_name domain.com www.domain.com;
access_log /var/log/access.log;
root /path/to/root;
location / {
index index.php index.html index.htm;
}
location / {
if ($internals) {
autoindex on;
}
}
}
Related
My ngix site config file is given below. I want to add context path to my URL
I can access site by http://localhost:8888, but I want to add context path to my site URL like http://localhost:8888/MyApp
server {
listen 8888;
server_name localhost;
location{
root "C:/nginx/Share/dist";
index index.html index.htm;
}
}
Thanks in advance
You need to change the base location for this
server {
listen 8888;
server_name localhost;
location / {
# since we have nothing on root we can redirect to /MyApp/ if we want
return 302 /MyApp;
}
location /MyApp {
root "C:/nginx/Share/dist";
index index.html index.htm;
}
}
I'm completely new to nginx. I've installed nginx on windows pc.
What I want to do is server a list of files in D:\ on localhost:8082/list.
If I use the following conf:
server {
listen 8082;
location / {
root D:/;
autoindex on;
}
}
I can correctly see what i want on localhost:8082. But if I change it to:
server {
listen 8082;
location /list {
root D:/;
autoindex on;
}
}
The page localhost:8082/list gives a 404 error.
What you need is alias instead of root.
server {
listen 8082;
location /list {
alias D:/; ##### use alias, not root
autoindex on;
}
}
See Nginx -- static file serving confusion with root & alias
I want to access specific folders that can access at http.
I am using like below code that specific file can access at http.
but i dont know how to apply Forders.
server {
listen 80;
ssl off;
server_name example.com www.example.com;
root /var/www/example;
location = /example1.txt{
# do stuff
}
location / {
return 301 https://$host$request_uri;
}
}
please let me know how to solve that problem.
thank you
You can use:
location /somedir {
autoindex on;
}
Is it possible to serve all requests to example.com ( and www.example.co)
from the root folder
location / {
root html;
index index.html index.htm;
}
but all requests to admin.example.com from a another folder 'admin' on the same server ?
The admin.example.com should be configured as a separate server in nginx config, but noone restricts you from pointing its root inside other server's root directory
server {
listen 80;
server_name admin.example.com;
root /some/path/example.com/admin;
location / {
index index.html;
}
}
server {
listen 80;
server_name www.example.com example.com;
root /some/path/example.com;
location / {
index index.html index.htm;
}
}
Use different server directives, this way:
server {
server_name admin.example.com;
root admin;
location / {
index index.html index.htm;
}
}
server {
server_name example.com;
root html;
location / {
index index.html index.htm;
}
}
Also, it is better to use only one root directive at server level, not to repeat it across location blocks (cf pitfalls).
I'm trying to upload a bunch of html and image files to my Nginx webserver which is running Ghost (the blogging platform) lets call it ghost-blog.com. Ghost runs perfectly fine, but additionaly I want serve other files and folders under the same domain e.g. ghost-blog.com/text.html and ghost-blog.com/subfolder/index.html.
After spending some time googling for an answer it seems I've bumped into something "new". I am aware I need to make changes to the /etc/nginx/sites-available/default file. What I don't know is what to add/edit so that
I create a /some/random/public folder public
This does not conflict with Ghost which is already serving content, specially the default index index.html index.htm files.
My current /etc/nginx/sites-available/default config file looks like this:
server {
listen 80;
server_name www.ghost-blog.com;
rewrite ^/(.*) http://ghost-blog.com/$1 permanent;
}
server {
root /usr/share/nginx/www;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}
Any suggestions on how I could go around creating a /public folder serving other files and sub-folders?
server {
listen 80;
server_name www.ghost-blog.com/subfolder;
rewrite ^/(.*) http://ghost-blog.com/subfolder/$1 permanent;
}
server {
root /usr/share/nginx/www/NEWSITEFOLDER;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}
then in ssh you need to make this directory to run the new ghost blog from
/usr/share/nginx/www/NEWSITEFOLDER;
so run command
mkdir /usr/share/nginx/www/NEWSITEFOLDER;