0

使用 morbo,为所有页面呈现静态文件。然而,使用 Nginx 作为代理的 hypnotoad 服务器会加载页面,但不会呈现其中的静态文件——即使是 favicon,但在同一个应用程序中调用静态 html 页面时,图像和 favicon 都会出现。可能缺少什么?

   upstream backendurl {
    server 127.0.0.1:8080  fail_timeout=0;
}

server {
  listen  80;
  listen [::]:80;
  server_name example.com www.example.com ;

  access_log /var/log/nginx/access.log;
  error_log  /var/log/nginx/error.log info;
  root /var/www/example.com/public;
 
  location / {
    try_files $uri @proxy;
    access_log off;
    expires max;
    add_header 'Access-Control-Allow-Origin' 'http://example.com';
  }
  

  location @proxy {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass       http://backendurl;
  }
}
4

1 回答 1

0

Apache2的解决方案给出了一些提示: https
://github.com/mojolicious/mojo/wiki/Apache-deployment 发现一个成功的Nginx解决方案如下:

upstream backendurl {
    server 127.0.0.1:8080  fail_timeout=0;
}
 
server {
  listen  443 ssl;
  listen [::]:443 ssl;
  server_name myexample.com www.myexample.com;
 
  access_log /var/log/nginx/access.log;
  error_log  /var/log/nginx/error.log info;
  root /home/sammy/simple_image/public;
  
  location / {
    try_files $uri @proxy;
    access_log off;
    expires max;
    add_header 'Access-Control-Allow-Origin' 'https://myexample.com';
  }
  
    location /static {
    try_files $uri @proxy;
    access_log off;
    expires max;
    add_header 'Access-Control-Allow-Origin' 'https://myexample.com';
  }
 
  location @proxy {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass       http://backendurl;
  }
  
    ssl_prefer_server_ciphers on;
      #add all the necessary ssl files, (eg .crt and key files) and links here
}
于 2021-04-29T19:26:41.873 回答