目前有一个带有一些嵌入式 JS 代码的纯 HTML 网站,用于控制 HTML 文件之间的流程以及图形配置细节。目录如下:html、css、fonts、img、js、sound。在我的本地机器上,我可以轻松打开 HTML 文件并浏览网站。我正在使用带有 nginx 作为反向代理的 Ubuntu Amazon EC2 实例。在实例上运行 express.js 控制的网站时,我通常只编辑 nginx 配置文件并启动 app/server.js 文件。但是,我不确定如何使用一组具有 CSS 和其他相关 Assets 的静态 HTML 文件来执行此操作。以下是我编写 nginx 文件的尝试,但我不确定我的建议是否可行。
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/website-dashboard/;
index index.html;
# Make site accessible from http://localhost/
server_name localhost;
location / {
default_type "text/html";
try_files $uri.html $uri $uri/ /index.html;
access_log off;
}
}
最佳答案
使用 NGINX 打开 HTML 文件应该没有问题 - 问题是,考虑到您正在将 NGINX 作为反向代理运行,您正在运行什么作为 Web 服务器?
如果您正在运行 Apache,那么您需要确保它在端口 8080 上运行,并且以下 NGINX 配置应该满足您的要求。
upstream apachebackend {
server 127.0.0.1:8080; #apachebackend
}
server {
listen 80 default;
server_name www.domain.com domain.com;
access_log /var/log/nginx/domain.com.access.log main;
error_log /var/log/nginx/domain.com.error.log;
root /usr/share/nginx/html;
index index.html index.htm index.php;
## send request back to apachebackend ##
location / {
proxy_pass http://apachebackend;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering on;
proxy_buffers 12 12k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
如果您正在运行 NGINX 作为您的 Web 服务器,那么您需要对其进行相应的设置。默认设置应该足够了,只需将文件放在默认的 vhost 目录中,但我建议使用单独的目录和日志文件正确设置它。
关于html - 具有多个静态子域的 Nginx 和 Amazon EC2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26290609/