我正在尝试设置 Nginx 来为用户显示公共文件夹中的文件。该站点将有多个用户,每个用户都有一个 Nginx 不知道其名称的子目录。
目录结构示例:
/users/usernameHere/public
/users/usernameHere/private
Run Code Online (Sandbox Code Playgroud)
我只希望 nginx 显示用户公共目录中的文件并拒绝对任何其他目录的所有访问。
这是我到目前为止所尝试的:
location ^~ /users/*/public/ {
allow all;
try_files $uri $uri/ =404;
}
location ^~ /users/ {
deny all;
}
Run Code Online (Sandbox Code Playgroud) 什么是在Nginx位置指令中做的波浪号(〜)?即:
location ~* \.(png|gif|jpg)$ {
[...configuration]
}
Run Code Online (Sandbox Code Playgroud) 我的nginx配置非常简单,内部有3个位置。他们每个人都有自己的根目录+我将来应该可以轻松添加另一个目录。
我想要的是:
请求/admin=>位置^/admin(/|$)
请求/admin/=>位置^/admin(/|$)
请求/admin/blabla=>位置^/admin(/|$)
请求/client=>位置^/client(/|$)
请求/client/=>位置^/client(/|$)
请求/client/blabla=>位置^/client(/|$)
请求/blabla=>位置/
请求/admin-blabla=>位置/
请求/client-blabla=>位置/
实际结果:
所有请求都转到了位置/。
我使用别名,try_files,根目录和正则表达式的不同组合尝试了来自文档,stackoverflow和其他来源的许多不同建议,但对我没有任何帮助。
仅当我尝试使用just return 200 'admin';并且return 200 'front'它按预期工作时。
最低配置:
server {
listen 80;
index index.html;
location / {
root /var/www/html/www_new/front;
try_files $uri $uri/ /index.html;
}
location ~ ^/admin(/|$) {
root /var/www/html/www_new/admin;
try_files $uri $uri/ /index.html;
} …Run Code Online (Sandbox Code Playgroud) 我对nginx完全陌生。我已经在Windows pc上安装了nginx。
我想要做的是服务器上的文件的列表D:\上localhost:8082/list。
如果我使用以下conf:
server {
listen 8082;
location / {
root D:/;
autoindex on;
}
}
Run Code Online (Sandbox Code Playgroud)
我可以正确看到我想要的东西localhost:8082。但是,如果我将其更改为:
server {
listen 8082;
location /list {
root D:/;
autoindex on;
}
}
Run Code Online (Sandbox Code Playgroud)
该页面localhost:8082/list给出了404错误。
Nginx 负责从根目录到根 URL 的所有静态内容。例如,如果根内容位置配置为/usr/share/nginx/html包含文件/usr/share/nginx/html/foo.html,则 urlhttp://localhost/foo.html将提供该 html 文件。我想在 URL 中添加上下文路径前缀,以便为文件http://localhost/myapp/foo.html提供服务。/usr/share/nginx/html/foo.html
我尝试更改位置并添加别名,但这给出了 404。
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /myapp/ {
alias /usr/share/nginx/html/;
}
Run Code Online (Sandbox Code Playgroud)
我也希望那http://localhost/myapp应该服务/usr/share/nginx/html/index.html
我正在使用 nginx 的1.12.1-alpinedocker 镜像
我在 docker 容器中运行 nginx。我想要一个子目录/web/来访问我的个人文件和项目。它还应该支持 php。
下面是我正在运行但domain-a.com/web一直导致 404。PHP 被确认工作,因为相同的 php 块在子域上工作但直接在server{}块中工作。
http {
server {
listen 443 ssl;
server_name domain-a.com domain-b.com;
# Mime types
include /etc/nginx/confs/mime.types;
# SSL
include /etc/nginx/confs/nginx-ssl.conf;
# Proxy to organizr
# This works
location / {
proxy_pass http://organizr/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_set_header Connection "";
}
# Root folder for my personal files/projects
# Doesn't work
location …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Nginx 中为一个 Angular 部署站点(我有一个带有 index.html 文件的 dist 目录)提供服务。在该目录中,我有:
我没有 Nginx 的经验,所以我试图正确地服务这个网站。我对该站点的配置是:
server {
listen 80;
server_name sibdomain.domain.com;
location ~* \.(?:css|js|map|jpe?g|gif|png)$ { }
location / {
root /var/www/multiapp/dist;
index index.html index.htm;
try_files $uri $uri/ =404;
if (!-e $request_filename){
rewrite ^(.*)$ /index.html?path=$1 break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/multiapp/dist;
}
}
Run Code Online (Sandbox Code Playgroud)
现在正在索引中加载的唯一文件,但 css 和 js 文件返回 404。在 apache 这个站点工作正常,我有这个规则:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# not …Run Code Online (Sandbox Code Playgroud) 我想将“.html”添加到以“/”结尾的每个文档中,主页除外。
\n\n我尝试了一些不同的方法,使用重写并使用 nginx 返回 301,但我没有\xc2\xb4t 无法使其工作。附上我所做的最后一个版本,它正在执行 /*/.html 但第二个 / 不应该在那里。
\n\nlocation / {\n try_files $uri $uri/ =404;\n return 301 $scheme://$host$request_uri.html;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我正在寻找的解决方案:
\n\nroot:domain.com 应作为 www.domain.com 传送
\n\n文件应重定向 (301) 到 *.html 版本
\n\n需要一些帮助来编写规则来阻止以下请求
有问题的网址是:
www.somesite.com/catalogsearch/result/?q=downloader
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法,但这不起作用
location ^~ catalogsearch/result/?q=downloader {
deny all;
}
Run Code Online (Sandbox Code Playgroud)
我“认为”是因为?包含问号是将 url 视为查询字符串吗??
问候
我写了这个/etc/nginx/conf.d/apply.conf并启动了nginx。
server {
location = /hoge {
return 200;
}
}
Run Code Online (Sandbox Code Playgroud)
但curl命令失败。
curl localhost:80/hoge
Run Code Online (Sandbox Code Playgroud)
它说
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.13.9</center>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
日志是
open() "/usr/share/nginx/html/hoge" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /hoge HTTP/1.1", host: "localhost"
Run Code Online (Sandbox Code Playgroud)
我只想返回没有响应正文或响应正文为空白的状态代码。
我改成这个但仍然不起作用。
location /hoge {
return 200 'Wow';
add_header Content-Type text/plain;
}
Run Code Online (Sandbox Code Playgroud)
也尝试过这个。
location /hoge {
return 200 'Wow';
default_type text/plain;
}
Run Code Online (Sandbox Code Playgroud)