我已经读到没有必要使用sites-enabled
,甚至没有看到它sites-enabled
。
无论如何,它的优点不是问题的一部分(因此,请考虑按主题进行的讨论)。
我想做的是设置一个绝对准系统的基本suggested not to use文件,该文件执行一些超级基本的用例工作:各种形式的重定向。
根据我的理解,此conf应该足够:
nginx.conf
不幸的是,我的例子不起作用。代理位有效,但子域似乎无效。老实说,我现在不相信server_name会做任何事情。
因此,如何编写一个简单的(无额外功能)nginx.conf文件来举例说明这些超级琐碎的功能(子域和反向代理)?
我在沙盒虚拟机上尝试了您的配置。 nginx拒绝启动,当我运行http {
# default server
server {
root /var/www/html/production-site;
# reverse proxy for external blog, makes example.com/blog display the blog. helps with SEO.
location /blog/ {
proxy_pass https://example.some-external-blog.com/;
}
}
# dev server
server {
server_name dev.example.com;
root /var/www/html/dev-site;
}
}
命令(在进行重大配置更改后,这总是一个好主意)时,它说:
nginx -t
所以我已经将nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] no "events" section in configuration
nginx: configuration file /etc/nginx/nginx.conf test failed
行添加到配置中。之后,nginx成功启动,并且一切都按预期工作。
[我不会跳过的另一件事是包括events {}
文件。因此,最终的最小配置如下所示:
mime.types