【问题标题】:Changing browser url in Nginx Unicorn Rails app on EC2在 EC2 上的 Nginx Unicorn Rails 应用程序中更改浏览器 URL
【发布时间】:2023-03-12 18:18:01
【问题描述】:

现在我在 Amacon EC2 上成功配置了一个 rails 应用程序。我成功配置了 nginx 和 unicorn,现在我可以看到这个 url 为myipaddress/login但想使用域名访问。 这是问题,因为我已经更改了 hosts 文件并在 ec2 实例中的 ssh 之后添加了以下内容:-

127.0.0.1 www.mysite.com
#Virtual Hosts
myipaddress www.mysite.com
myipaddress mysite.com

我的/home/ubuntu/shareit/config/nginx.conf 文件也是这样的:-

upstream unicorn {
  server unix:/home/ubuntu/shareit/tmp/sockets/unicorn.shareit.sock fail_timeout=0;
}

server {
  listen 80;
  #listen [::]:80 ipv6only=on default_server;
  server_name mysite.com www.mysite.com;
  root /home/ubuntu/shareit/public;

  access_log /home/ubuntu/shareit/log/access.log;
  error_log  /home/ubuntu/shareit/log/error.log;



  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

但当我尝试点击 url www.mysite.com 而不是 myipaddress/login(正在工作)时,我仍然会收到错误,因为 此网页不可用

所以我错过了什么吗?我不想使用 ipaddress 访问我的应用程序。我什至尝试在 routes.rb 中使用应用程序名称,但它仍然无法正常工作。 我什至使用sudo /etc/init.d/nscd restart 刷新了 UBUNTU dns 并重新启动了 nginx 和 unicorn,但它不起作用?

任何帮助将不胜感激?

【问题讨论】:

    标签: ruby-on-rails ubuntu nginx amazon-ec2 unicorn


    【解决方案1】:

    的输出是什么
    ping myipaddress www.mysite.com
    

    如果能够正确解析,设置Route53,所有配置似乎都ok,你只需要一个“A”记录

    【讨论】:

      【解决方案2】:

      您的域名是否在您的服务器“A”记录 ip 中注册?

      您需要为您的域名设置一条 A 记录,以指向您服务器的 IP 地址。

      您可以通过此链接使用服务器 ip (https://aws.amazon.com/blogs/aws/aws-management-console-now-supports-amazon-route-53/) 注册您的域,其中提供了在注册商处注册域并在 Route 53 中进行设置的整个过程,包括进一步的说明。

      【讨论】:

      • 欢迎来到 Stack Overflow!如果有更长的解释和指向有用参考的链接,这个答案会更有用。请参阅How to Answer 帮助页面。
      • 除了使用 ROUTE53 没有别的办法吗? @Sasidaran
      猜你喜欢
      • 2016-01-07
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多