我在/ etc / nginx / sites-enabled中有一些关于这个configuration文件“default”的问题。 如下所示。
server { root /usr/share/nginx/www; index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { proxy_pass http://127.0.0.1:8080; } location /doc { root /usr/share; autoindex on; allow 127.0.0.1; deny all; } location /images { root /usr/share; autoindex off; } }
只是一个快速的声明:site-enabled / sites-available布局不是来自nginx本身,而是来自你的包维护者。 默认情况下,nginx提供了单个的nginx.conf示例configuration,比在一些linux包中find的多个通过includejoin的文件更加明显。 这里是按顺序的答案:
没有“听”指令,它怎么知道默认为80
这是因为nginx默认侦听端口80(或8000,如果以非root用户身份运行),请参阅http://nginx.org/r/listen 。
server_name是localhost,另一个域如何工作?
默认情况下,nginx使用configuration中的第一个server作为默认server (并使用它来处理与其他服务器server_name指令不匹配的域)。 只要站点启用/默认是您的configuration中唯一的服务器 – 它实际上将作为默认的工作。 如果你要添加更多的服务器 – 它可能会中断。 请参阅http://nginx.org/en/docs/http/request_processing.html上的详细说明。
为什么位置指令embedded在服务器指令中? 这是否意味着这些位置只适用于此服务器?
是的, location指令只能在某个特定的server指定,只适用于与此服务器匹配的请求。
我的configuration没有听80 default_server; 那么nginx如何select使用什么configuration?
在config中find的第一个服务器块将是默认的。 由于include通配符并不强制任何sorting,它可能会是一些随机的服务器块。