tporto

tporto

When accessing the page she tries to load lasts about 10 seconds and reloads again and stays in that loop without stopping. When accessing the server I saw that at each attempt it shows this message in the log:

[error] Could not check origin for Phoenix.Socket transport.
Origin of the request: http://www.autoplacasma.com.br
This happens when you are attempting a socket connection to
a different host than the one configured in your config/
files. For example, in development the host is configured
to “localhost” but you may be trying to access it from
“127.0.0.1”. To fix this issue, you may either:

  1. update [url: [host: …]] to your actual host in the
    config file for your current environment (recommended)
  2. pass the :check_origin option when configuring your
    endpoint or when configuring the transport in your
    UserSocket module, explicitly outlining which origins
    are allowed:
    check_origin: [“https://example.com”, “//another.com:888”, “//other.com”]

prod.exs

config :autoplacas, AutoplacasWeb.Endpoint,
  http: [port: 80],
  url: [host: "autoplacasma.com.br", port: 80],
  check_origin: ["//autoplacasma.com.br"],
  code_reloader: false,
  cache_static_manifest: "priv/static/cache_manifest.json"

releases.exs

config :autoplacas, AutoplacasWeb.Endpoint,
  http: [:inet6, port: 80],
  secret_key_base: "mysecret",
  server: true,
  pubsub_server: Autoplacas.PubSub,
  live_view: [signing_salt: "mysalt"]

Showing Posts 1 to 10

hectorsq

hectorsq

Have you tried adding this

to releases.exs?

Is it already hosted at autoplacasma.com.br or is it in your local host?

Are you running it with mix phx.server or are you running the release?

tporto

tporto OP

It is in production. It was generated via releases. Hosted on autoplacas.com.br

tporto

tporto OP

I made this change and keeps giving the same message

hectorsq

hectorsq

This may seem obvious but which command are you using to run your app?

tporto

tporto OP

Service (I don’t use nginx):

[Unit]
Description=Phoenix server for DeployPhoenix app
After=network.target

[Service]
User=root
Group=root
Restart=on-failure
RestartSec=5
WorkingDirectory=/home/phoenix-autoplacas
ExecStart=/home/phoenix-autoplacas/_build/prod/rel/autoplacas/bin/autoplacas start
ExecStop=/home/phoenix-autoplacas/_build/prod/rel/autoplacas/bin/autoplacas stop

[Install]
WantedBy=multi-user.target

releases.exs

config :autoplacas, AutoplacasWeb.Endpoint,
  http: [:inet6, port: 80],
  url: [host: "autoplacasma.com.br", port: 80],
  secret_key_base: "mysecret",
  server: true,
  check_origin: ["//autoplacasma.com.br"],
  pubsub_server: Autoplacas.PubSub,
  live_view: [signing_salt: "mysalt"]
hectorsq

hectorsq

Comparing with my configuration in releases.exs I found the following differences

  1. I do not have the check_origin key
  2. I do not specify the port in the url key
  url: [host: "autoplacasma.com.br"],

instead of

  url: [host: "autoplacasma.com.br", port: 80],
padmaJS

padmaJS

Can I ask what check_origin actually is and what does it do?

riccardomanfrin

riccardomanfrin

I might be totally off track, but I think yours is the key question. Because I was fooled as well I’d like to elaborate:

From doc:

`:check_origin` - if the transport should check the origin of requests 
when the `origin` header is present

Now the “origin” header from first random doc:

indicates the origin (scheme, hostname, and port) that **caused** the request

Caused… which is the website itself you connected to in the first place (ah-ah moment to me.. this explains why I find domain names in the “check_origin”!)

BUT assuming you have a config such this

config :mygoodservice, MyGoodService.Endpoint,
  https: [
    port: 8443,
    ...
  ],
  url: [host: "mygoodservice.com"],

What is the proper origin? You are conveniently told that by the console error (which I got with the default check_origin: true config):

[error] Could not check origin for Phoenix.Socket transport.
Origin of the request: https://mygoodservice.com:8443

I suspect that just letting the default value true is not actually defaulting to the origin you are prompted about in the console :man_shrugging: .. (maybe it’s forgetting the port? or I’m doing bad somwhere else… dunno).

Anyway setting the whole exact string reported by the console solved for me!
Also: if you are troubleshooting start/stop/restarting your service, I’d close the tab and open a new one.. for what is worth I’ve seen strange things happening on firefox (which might well be consequence of me doing this late night).

Cheers

KevinGenus

KevinGenus

I’m late to the game, but using Phoenix v1.7.11 on Fly.io the following showed up in my logs:

This happens when you are attempting a socket connection to a different host than the one configured in your config/files. For example, in development the host is configured
to "localhost" but you may be trying to access it from "127.0.0.1". To fix this issue, you may either:
1. update [url: [host: ...]] to your actual host in the config file for your current environment (recommended)
2. pass the :check_origin option when configuring your endpoint or when configuring the transport in your UserSocket module, explicitly outlining which origins are allowed:
check_origin: ["https://example.com", "//another.com:888", "//other.com"]

I added check_origin: ["https://my_domain.com"] and it worked.

smahi

smahi

@KevinGenus
In which config file did you set the check_origin value?

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews