【问题标题】:Nginx not showing railsapp but instead showing Plesk default pageNginx 不显示 railsapp 而是显示 Plesk 默认页面
【发布时间】:2018-04-17 07:06:34
【问题描述】:

我一直在尝试让我的 vps 根据本教程运行我的 railsapp:https://gorails.com/deploy/ubuntu/16.04

设置是创建一个部署服务器,我可以在其中使用 ssh 部署我的 rails 应用程序。就像部署到 Heroku 一样。

此时,一切似乎都在运行,没有任何错误。 Nginx 显示了这一点。

deploy@localhost:~$ sudo service nginx status
[sudo] password for deploy: 
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-04-16 21:06:26 CEST; 11h ago
  Process: 1670 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
  Process: 1666 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry TERM/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 1677 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 1674 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 1680 (nginx)
    Tasks: 3
   Memory: 7.0M
      CPU: 69ms
   CGroup: /system.slice/nginx.service
           ├─1680 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           ├─1681 nginx: worker process                           
           └─1682 nginx: worker process                           

Apr 16 21:06:26 localhost systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 16 21:06:26 localhost systemd[1]: Started A high performance web server and a reverse proxy server.

但由于某种原因,当我在浏览器中访问服务器的 IP 地址时,我得到了 Plesk 的默认页面。在我的 Linux Ubuntu 16.04 服务器上安装了哪个标准 Web 平台。

我认为 /etc/nginx/sites-enabled/default 一定是问题所在。这是现在的样子:

server {
        listen 80;
        listen [::]:80 ipv6only=on;

        server_name mydomain.com;
        passenger_enabled on;
        rails_env    production;
        root         /home/deploy/palazon/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

然后我发现还有 /etc/nginx/sites-available/default 通常会显示默认的 nginx 页面。看起来是这样的:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;

   #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

最后这是 /etc/nginx/nginx.conf 显示的内容:

user deploy;

worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
#       ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

       # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Phusion Passenger config
        ##
        # Uncomment it if you installed passenger or passenger-enterprise
        ##


        include /etc/nginx/passenger.conf;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

有人知道我是如何不断获得 Plesk 默认页面的吗?我的 rails 应用程序已经通过 capistrano 成功部署:cap production deploy

我发现我所有的应用程序文件都在服务器上。所以只缺少一个最终链接,我还没有找到它。有人知道它是什么吗?

感谢您的支持。

【问题讨论】:

    标签: ruby-on-rails nginx plesk


    【解决方案1】:

    每次更改配置时,都必须重新启动服务才能应用更改。 我也更喜欢使用本地 DNS 和 nginx 的块(相当于 apache 的虚拟主机),这样你就可以运行多个站点。

    【讨论】:

    • 我一直在使用“sudo service nginx restart”重新启动 ninx,但这似乎没有效果。以及如何使用本地 DNS 和 nginx 块?
    • 您需要做的就是在您的主机文件中使用静态 DNS 条目,这些条目针对您的开发服务器。然后添加一些具有相关名称的块。
    【解决方案2】:

    根据 Ubuntu(或 Debian)Apache 和 Nginx 配置结构,要激活域配置,您应该在 /sites-enabled/ 中拥有它。 通常/sites-available/中有指向同一个配置文件的符号链接:

    # ls -la /etc/nginx/sites-enabled/
    lrwxrwxrwx 1 root root   35 Sep 17  2016 example.com.conf -> ../sites-available/example.com.conf
    

    那么您很可能会遇到权限问题。确保您的 ./public 目录可供 nginx 用户访问。

    Plesk Onyx 随附 Ruby on Rails、Passenger 和 PostgeSQL。您可以调整此指令以通过 Plesk GUI 执行所有操作。我建议从头开始,制定以下行动计划:

    1. 确保您在 Plesk Onyx 上并且必要的组件是安装程序(即 nginx、Ruby、Posgre)。如果需要,更新/安装。
    2. 为 Capistrano 创建 Gemfile 和安装脚本。您将在此处找到 RoR 应用程序部署的视频示例 - https://www.plesk.com/extensions/ruby/
    3. 您很可能会发现您的 Nginx 配置已准备就绪。否则,我建议在 Apache and Nginx Settings > Additional Nginx Directives 中添加必要的指令,注意全局配置中已经存在的指令。它会为你做一个简单的语法检查。
    4. 创建一个数据库,然后在应用程序中设置连接字符串。

    【讨论】:

    • 感谢您的回答。我完全赞成最痛苦的解决方案。如果那是 Plesk Onyx,那么我会这样做。我只是不知道如何进入他们的 GUI。我一直只使用我的终端 (mac) 和 ssh 来配置我的 vps。你能告诉我你是怎么上去的吗?
    • 如何检查 ./public 目录是否可供 nginx 用户访问?
    • 在 root 下通过 SSH 运行 # plesk login 命令。这将为您提供一次性登录链接。粘贴到浏览器地址栏。然后检查您的管理员凭据并创建一个域。
    • 公共文件夹至少应该对www-data 用户或组可读。当通过 Plesk 部署 Ruby 应用程序时,您的公共目录将位于具有其自己的专用系统用户的虚拟主机目录中,因此不需要额外的操作。
    • 我这样做了,但连接超时。我认为 Plesk 有问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多