我已阅读过文档,扫描的示例,但我不知道为什么这不起作用。我对nginx完全陌生,所以如果这是一个愚蠢的简单答案,请轻松点我。Nginx忽略位置指令?
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
#include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name localhost domain.com;
root /home/TMlabs/server_files;
index index.html index.htm;
location = /othersite {
root /home/TMlabs/server_files/location2;
index index.html index.htm;
}
location/{
root /home/TMlabs/server_files/location1;
index index.html index.htm;
}
}
如果我需要包括更多,让我知道,我会转储整个nginx.conf。不过,这很基本。
我想要实现的所有功能都是将domain.com映射到位置/(正在工作)中指定的根,并将domain.com/othersite映射到该指令中指定的根。出于某种原因,当我导航到domain.com/othersite而不是/ home/TMlabs/server_files/location2文件夹中的index.html文件时,它会返回/home/TMlabs/server_files/location1/index.html文档。我试过去除了等号并使用可用于匹配的不同运算符,但似乎没有任何工作。这可能是一些非常基本的东西,我误解了这些东西。我也吮吸正则表达式。任何人都在照顾开导?
编辑:我认为发生的事情是,它实际上完全忽略了我的指令,只是简单地使用/ usr/share/nginx/www作为文档根目录。我没有在任何地方看到这个配置;我错过了什么?
我想你可能过于简化您的示例配置为必须有别的事情上那里得到这一结果。请张贴更详细的信息。其余加入 – Dayo
。我正在从一个模板开始工作,这就是其余部分。 –
在上面发布的完整配置中,您错过了http块的右括号。 此外索引指令是继承的,所以不需要在每个位置块中重复它。而=/othersite意味着只有特定的/别人的url匹配,而不是任何可能不是你想要的子页面。 – cobaco