Search code examples
rustrust-rocket

Webserver only launches from http://localhost:8000


I'm running this hello world example:

https://rocket.rs/v0.4/guide/quickstart/#running-examples

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 1.32s
     Running `C:\Users\m3\repos\Rocket\target\debug\hello_world.exe`
Configured for development.
    => address: localhost
    => port: 8000
    => log: normal
    => workers: 8
    => secret key: generated
    => limits: forms = 32KiB
    => keep-alive: 5s
    => read timeout: 5s
    => write timeout: 5s
    => tls: disabled
Mounting /:
    => GET / (hello)
Rocket has launched from http://localhost:8000

The code is available here:

https://github.com/SergioBenitez/Rocket/tree/v0.4/examples/hello_world

Problem

The problem is it only launches from http://localhost:8000. It doesn't work for http://127.0.0.1:8000 or http://192.168.1.250:8000.

Question

How can I modify the code to make the server launch from 127.0.0.1 or the static IP address of the server i.e. 192.168.1.250? I examined the code, but couldn't figure out how.

Didn't work

Modifying Cargo.toml config and adding address and port:

[global]
address = "0.0.0.0"
port = 80

Solution

  • A quick glance at the documentation mention a file named rocket.toml

    Try to put the configuration in a file named Rocket.toml

    [global]
    address = "0.0.0.0"
    port = 80
    

    or for IPv6 (which should accept IPv4 too)

    [global]
    address = "::"
    port = 80