【发布时间】:2017-09-29 17:08:42
【问题描述】:
我正在使用 Angular 2 应用程序、nginx 和 docker。每次我用 /site 重新加载页面时,它都会给我一个 404。我的服务器块现在看起来像这样:
server {
listen 0.0.0.0:80;
listen [::]:80;
root /var/www/project/html;
index index.html;
server_name project.com;
location / {
try_files $uri $uri/ /index.html;
}}
我已经尝试了很多,并且已经看到了所有其他 stackoverflow 问题并且尝试了所有可能性。但没有任何效果。有人可以帮忙吗?
更新: 整个 nginx.conf:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
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;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
网站启用/默认:
server {
listen 0.0.0.0:80;
listen [::]:80;
root /var/www/project/html;
index index.html;
server_name project.com;
location / {
try_files $uri $uri/ /index.html;
}}
还有 Dockerfile:
FROM nginx
COPY ./docker/sites-enabled /etc/nginx/sites-enabled
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
COPY ./dist /var/www/project/html
COPY ./dist /usr/share/nginx/html
EXPOSE 80
【问题讨论】:
-
你有任何错误日志吗?
-
@Moema 只有错误日志:“加载资源失败:服务器响应状态为 404(未找到)”。没有别的了。
-
我的意思是您可以在 nginx.conf 中配置的 Nginx 错误日志(请参阅nginx.com/resources/admin-guide/logging-and-monitoring)我认为默认情况下它们位于 /var/log/nginx/
-
我必须在我的 docker 中打开日志,但它没有打开。甚至 vim 都说,那个 error.log 不是一个文件
-
因此您的服务器块看起来绝对正确(假设您的 index.html 位于 /var/www/project/html) - 也许这是您的 docker 设置的问题。你能发布整个 nginx.conf 和你的 dockerfile 吗?