Jak zmienić domyślny port aplikacji Rails 4?
Wiem, że mogę uruchomić serwer rails na innym porcie poprzez opcję -p
. Ale chciałbym ustawić inny port na aplikację, o ile uruchomię webrick.
Pozdrawiam Felix
5 answers
Szybkie rozwiązanie: Dołącz do Rakefile
task :server do
`bundle exec rails s -p 8080`
end
Następnie uruchom rake server
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-08 17:01:06
Dodaj to do config/boot.rb
:
require 'rails/commands/server'
module DefaultOptions
def default_options
super.merge!(Port: 3001)
end
end
Rails::Server.send(:prepend, DefaultOptions)
Uwaga: ruby >= 2.0 wymagane.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-25 10:00:02
Wariant 1:
Możesz uruchomić WEBrick Tak:
rails server -p 8080
Gdzie 8080 jest Twoim portem. Jeśli chcesz, możesz wrzucić to do skryptu bash dla wygody.
Opcja 2:
Możesz zainstalować $ gem install foreman
i użyć Foremana do uruchomienia serwera produkcyjnego (np. unicorn), jak zdefiniowano w Procfile
w następujący sposób: $ foreman run web
. Jeśli Unicorn jest twoim serwerem WWW, możesz określić port w pliku konfiguracyjnym unicorn(jak w przypadku większości opcji serwera). Korzyści z tego podejścia jest nie tylko można Ustaw port w konfiguracji, ale używasz środowiska, które jest bliżej produkcji.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-08 07:55:29
Jeśli ustawisz domyślne opcje na {[2] } , wszystkie atrybuty komend rake i rails zawiodą (przykład: rake -T
lub rails g model user
)! dodaj to do bin/rails
po linii require_relative '../config/boot'
i Kod zostanie wykonany tylko dla polecenia rails server:
if ARGV.first == 's' || ARGV.first == 'server'
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
end
Plik bin/rails
wygląda tak:
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
# Set default host and port to rails server
if ARGV.first == 's' || ARGV.first == 'server'
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
end
require 'rails/commands'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-09 10:27:26
Dla Rails 5.1:
# config/boot.rb
# ... existing code
require 'rails/command'
require 'rails/commands/server/server_command'
Rails::Command::ServerCommand.send(:remove_const, 'DEFAULT_PORT')
Rails::Command::ServerCommand.const_set('DEFAULT_PORT', 3333)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-20 08:17:02