【发布时间】:2020-01-14 23:47:42
【问题描述】:
我正在设置一个新服务器,我想使用 Nginx 来部署我用 Angular 编写的应用程序。 nginx 配置应该是什么样子的?
这是一个新的 VPS OVH 服务器。我已经在这台服务器上安装了 Nginx,然后当我进入“my-app.com”时,我尝试配置 Nginx 以显示静态 index.html。不幸的是,我总是收到“无法访问此页面”的错误消息。
我正在传递我的配置:
nginx-conf:
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
}
http {
include /etc/nginx/mime.types;
default_type application.octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
然后我在 conf.d 中获得了 2 个额外的配置:
default.conf
server {
listen [::]:80;
server_name my-api.com www.my-api.com;
root /var/www/html;
index index.html;
try_files $uri $uri/ /index.html;
}
好的,最后一个:
my-app.com.conf
server {
listen [::]:80;
server_name my-api.com www.my-api.com;
root /var/www/html;
index index.html;
try_files $uri /index.html;
}
在命令之后: nginx -T (测试没问题),然后我通过“sudo service nginx stop”命令停止 Nginx 并再次启动它。进入浏览器并传递链接“my-app.com”后,错误仍然存在。我的预期结果只是来到这个页面“my-app.com”并查看我的应用程序。即使是静态 HTML - 这也会告诉我我做的是正确的。
感谢您的帮助!
【问题讨论】:
标签: nginx server devops nginx-config