Changing server ip and port in dev environment


#1

I used installation from here: Beginners Guide to Install Discourse on Ubuntu for Development

how can I change the IP and port? the server currently listens on localhost:3000 and I have to use it remotely

Thanks


(Rafael dos Santos Silva) #2

bundle exec rails server -b 0.0.0.0:3000


#3

not working. I get the following error. I’m running as root and tried several ports.

root@IL-SHARELOCK:~/discourse# bundle exec rails server -b 40.113.124.28 -p 1236
=> Booting Thin
=> Rails 4.2.4 application starting in development on http://40.113.124.28:1236
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 40.113.124.28:1236, CTRL+C to stop
Exiting
/home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:534:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:534:in `start_server'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/backends/tcp_server.rb:16:in `connect'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/backends/base.rb:63:in `block in start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `call'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `run_machine'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `run'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/backends/base.rb:73:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/server.rb:162:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:in `run'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
root@IL-SHARELOCK:~/discourse#

(Rafael dos Santos Silva) #4

Use 0.0.0.0 as the IP to bind to.


#5

Thank you @Falco. Indeed this solves that error message. But still it doesn’t work for me -

When I run “bundle exec rails server -b 0.0.0.0 -p 80” as root I get this error in the browser:

ActiveRecord::NoDatabaseError
FATAL: role "root" does not exist
Extracted source (around line #10):
    call_without_quiet_assets(env).tap do
      Rails.logger.level = previous_level
    end
  end

and when I run as my discourse user (which has root privileges) I get this error in the console:

smarko@IL-SHARELOCK:~/discourse$ bundle exec rails server -b 0.0.0.0 -p 80
=> Booting Thin
=> Rails 4.2.4 application starting in development on http://0.0.0.0:80
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 0.0.0.0:80, CTRL+C to stop
Exiting
/home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:534:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:534:in `start_server'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/backends/tcp_server.rb:16:in `connect'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/backends/base.rb:63:in `block in start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `call'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `run_machine'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `run'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/backends/base.rb:73:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thin-1.6.4/lib/thin/server.rb:162:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:in `run'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /home/smarko/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

(Rafael dos Santos Silva) #6

Try an unprivileged port like 9000.

There is no reason to run Discourse on port 80. To achieve that, use a reverse proxy or, for test purposes only, some ip tables routing.


#7

Thanks, it works with port 9000.
But for production, any other idea (other than using a reverse proxy…) of using port 80?
Do I have to install discourse for ‘root’ in order to use port 80?


(Rafael dos Santos Silva) #8

For production you use the recommended setup with docker and all is taken care of :wink:

If this is too much to handle right now, you can get Discourse team 99$ install, Digital Ocean 1-click or Discourse Hosting offerings.

I really recommend following defaults unless you are a power user. And power users should know about using ip tables, nginx reverse proxy, and never running as root on production.


#9

If I understand correctly, using dev env for development and docker for production, will limit my development to adding plugins.
So - what are the limits of plugins? what can not be done with them?


(cpradio) #10

The only limitation I’ve experienced thus far is you can’t alter the docker nginx templates/files from a plugin. That has to be done manually with the installation of a plugin or after the plugin is installed.

Think along the lines of adding a reverse proxy, not along the lines of adding a route (that is supported)