服务器无法看到用Brunch编译的静态资产(Phoenix Framework)
我有最奇怪的技术问题。虽然我的网站在开发过程中工作正常,并且过去在生产环境中工作正常,但在最后一次构建过程中,它已经莫名其妙地停止了对静态资产的识别,并且正在将老版本的favicon用于讨价还价。我甚至试图重新制作整个回购,但我遇到了完全相同的问题。旧的favicon甚至不存在于回购中。服务器无法看到用Brunch编译的静态资产(Phoenix Framework)
我在牛仔服务器进程的前一个nginx的反向代理,具有以下配置:
upstream phoenix {
server 127.0.0.1:4000;
}
# Default server configuration
#
server {
listen 80;
server_name haaksploits.com www.haaksploits.com;
return 301 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl http2;
listen [::]:443 ssl http2;
rewrite ^/(.*)/$ /$1 permanent;
server_name haaksploits.com wwww.haaksploits.com;
ssl_certificate /etc/letsencrypt/live/haaksploits.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/haaksploits.com/privkey.pem;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
access_log /var/log/nginx/sub.log combined;
root /var/www/haaksploits.com/html;
# Add index.php to the list if you are using PHP
index index.html index.php index.htm;
location/{
allow all;
# Proxy Headers
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Cluster-Client-Ip $remote_addr;
# WebSockets
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://phoenix;
include /etc/nginx/mime.types;
}
location ~ /.well-known {
allow all;
}
# Enable browser caching
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~* \.(pdf)$ {
expires 10d;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
正如你所看到的,我已经启用缓存,但我试过这个设置为一秒并没有任何帮助,并且无论如何我在之前上传了新的图标,因为它没有问题。我mix.exs:
defmodule Haaksploits.Mixfile do
use Mix.Project
def project do
[
app: :haaksploits,
version: "0.2.3",
elixir: "~> 1.4",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
start_permanent: Mix.env == :prod,
aliases: aliases(),
deps: deps()
]
end
def application do
[
mod: {Haaksploits.Application, []},
extra_applications: [:logger, :runtime_tools, :ueberauth, :ueberauth_google]
]
end
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
defp deps do
[
{:phoenix, "~> 1.3.0"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.2"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.10"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:ueberauth_google, "~> 0.2"},
{:ja_serializer, "~> 0.11.2"},
{:guardian, "~> 0.14.2"}
]
end
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
"test": ["ecto.create --quiet", "ecto.migrate", "test"]
]
end
end
而且我prod.exs:
use Mix.Config
config :haaksploits, HaaksploitsWeb.Endpoint,
http: [port: 4000],
url: [host: "haaksploits.com", port: 80],
cache_static_manifest: "priv/static/cache_manifest.json",
server: true,
code_reloader: false
config :logger, level: :info
import_config "prod.secret.exs"
我能想到的唯一的另一件事是,在最后的构建之前,发生问题出现了一个错误,说酒厂是错过了,所以我重新添加它以完成构建。我此后删除了Distillery和Edeliver,因为此刻我并不需要它们,虽然问题没有消失,但我不知道这是否对文件做了些什么,导致服务器查看错误资产的位置。
如果是这样的话,我真正需要的是知道Distillery正在寻找这些文件的位置,以及如何让Phoenix重新找到适合静态资产的位置。或者,如果以某种方式阻止访问,则允许访问文件。
当我查看/ priv/static时,所有文件都是它们应该在的位置。后
我的机器上测试没有nginx的,它似乎并没有成为凤凰/酒厂的问题,而是事做Nginx的配置。因此,也许一个缓存的问题:
更新所有........
更新:
如此,因为它当你的nginx的方程完全静止失败是没有问题的。使用早午餐或酿酒厂构建发行版时,它也失败,但仅在两个生产服务器(一个Debian,一个Ubuntu)上,而不是在我的开发Mac上。我正在尝试在我的开发环境中构建,然后将构建的tarball手动扫描到生产环境。
更新:
压缩包解失败,因为开发机及生产机器之间的结构上的差异。试图使用edeliver来规避。
更新:
似乎是工作的罚款时,该过程从IP地址直接访问,所以离开了我能想到的唯一的事情就是这件事情的The域名解析阶段之间的脚麻,和访问静态资产。留下edeliver解决方案,而是尝试使用Cloudflare,看看是否有帮助。
这个问题的源代码(至少对于我的主服务器来说,似乎有另外一个问题导致了另一个错误,这很奇怪,但是meh)最终导致SSL证书出错,导致访问被阻止到只有一些内容(???)。
我清除了所有的nginx设置,删除了所有certbot SSL设置,为Cloudflare签名并启用了SSL服务。这解决了这个问题。