小编Moe*_*ema的帖子

nginx.conf 中的 try_files 不起作用

我正在使用 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;
}}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了很多,并且看到了所有其他 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; …
Run Code Online (Sandbox Code Playgroud)

nginx docker angular

3
推荐指数
1
解决办法
7332
查看次数

标签 统计

angular ×1

docker ×1

nginx ×1