nginx Windows:设置站点可用配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13070986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nginx Windows: setting up sites-available configs
提问by Marc
I'm trying to set up Nginx on my Windows development environment. I can't find how to create something similar to "sites-enabled"
on Linux where Nginx would look for (links to) active virtual host configurations.
我正在尝试在我的 Windows 开发环境中设置 Nginx。我找不到如何"sites-enabled"
在 Linux 上创建类似于Nginx 会在其中查找(链接到)活动虚拟主机配置的内容。
Is there a way to do something similar with a directory with shortcuts to the actual configuration files and Nginx scanning that directory? Or is there another way to hook up a virtual host configuration other than copying the host configuration to nginx.conf
?
有没有办法对带有实际配置文件和 Nginx 扫描该目录的快捷方式的目录做类似的事情?或者除了将主机配置复制到之外,还有其他方法可以连接虚拟主机配置nginx.conf
吗?
采纳答案by Maxim Dounin
The "sites-enabled" approach as used by some Linux packages of nginx utilize include
directive, which understands shell wildcards, see http://nginx.org/r/include. You may use it in your own config as well, e.g.
nginx 的某些 Linux 软件包使用的“启用站点”方法使用include
指令,它理解 shell 通配符,请参阅http://nginx.org/r/include。您也可以在自己的配置中使用它,例如
http {
...
include /path/to/sites/*.conf;
}
Note though that such approach might be very confusing (in particular, it would be hard to tell which server{} is the default one unless you use default_server
explicitly).
请注意,这种方法可能非常令人困惑(特别是,除非您default_server
明确使用,否则很难判断哪个服务器{} 是默认服务器)。
回答by Umanda
In windows you have to give full path of the directory where the config files are located. There are two files to update: nginx.conf, which tells nginx where to find web sites, and localhost.conf, which is the configuration for a web site.
在 Windows 中,您必须提供配置文件所在目录的完整路径。有两个文件需要更新:nginx.conf,它告诉 nginx 在哪里可以找到网站,以及 localhost.conf,它是网站的配置。
It is assumed that nginx is installed in C:\nginx
. If the installation directory is at another path, you will have to update that path accordingly, wherever it appears in the following two configuration files.
假设 nginx 安装在C:\nginx
. 如果安装目录位于其他路径,则必须相应地更新该路径,无论它出现在以下两个配置文件中的任何位置。
nginx.conf
配置文件
Location: C:\nginx\conf
地点: C:\nginx\conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#to read external configuration.
include "C:/nginx/conf/sites-enabled/*.conf";
}
localhost.conf
本地主机配置文件
Location: C:\nginx\conf\sites-enabled
地点: C:\nginx\conf\sites-enabled
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
回答by Ryan
The following worked for me but only AFTER I moved my main nginx exe folder from c:/Program Files (x86)/nginx-1.7.0
to c:/nginx-1.7.0
(because I think it doesn't handle spaces in file paths well):
以下对我有用,但只有在我将我的主要 nginx exe 文件夹从 移动c:/Program Files (x86)/nginx-1.7.0
到之后c:/nginx-1.7.0
(因为我认为它不能很好地处理文件路径中的空格):
http {
...
include "f:/code/mysite/dev-ops/nginx/dev/mysite.conf";
}
回答by Flow
You can include your config with a relative path in your nginx.config (the relative path is just the path of the config file itself in contrast to the logs path for example):
您可以在 nginx.config 中包含带有相对路径的配置(例如,相对路径只是配置文件本身的路径,而不是日志路径):
http {
include mime.types;
default_type application/octet-stream;
include ../sites-enabled/*.conf;
...
}