我读到没有必要使用sites-enabled https://stackoverflow.com/questions/41303885/nginx-do-i-really-need-sites-available-and-sites-enabled-folders,甚至还看到过建议不要使用 https://serverfault.com/a/870709/547377.
无论如何,它的优点不是问题的一部分(所以请考虑偏离主题的讨论)。
我想做的是建立一个绝对准系统的基础nginx.conf
文件,它执行一些超级基本的用例内容:各种形式的重定向。
根据我的理解,这个conf应该足够了:
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;
}
}
不幸的是,我的例子不起作用。代理位可以工作,但子域似乎不起作用。老实说,我不相信 server_name 此时有任何作用。
那么,如何编写一个简单(无额外)的 nginx.conf 文件来举例说明这些超级琐碎的功能(子域和反向代理)?
我在我的沙箱虚拟机上尝试了你的配置。 nginx 拒绝启动,当我运行时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
所以我添加了events {}
行到配置。之后 nginx 成功启动并且一切都按预期工作。
我不会跳过的另一件事是包括mime.types
文件。所以最终的最小配置如下所示:
events {}
http {
include mime.types;
# 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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)