質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

2回答

5274閲覧

[Rails] Apache + Passengerでのdevelopment環境において、トップページのhtmlしか表示されない

ponsea

総合スコア15

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2017/01/22 05:20

編集2017/01/22 06:39

Apache + Passenger でのdevelopment環境で、クライアントPCからアクセスしても、トップページのhtmlの部分だけ表示されます。
それ以外のcssなどは、Not Foundになります。(ブラウザのコンソールのメッセージ)

また、その他のページにアクセスしたらNot Foundと表示されます。


バージョン
OS Centos7
Rails 5.0.1
Apache 2.4.6
Passenger 5.0.30

http://アプリケーション名.ホスト名/
のバーチャルホストの設定でアクセスするようにしています。

/etc/httpd/conf.d/vhost.conf

<VirtualHost *:80> ServerName <アプリケーション名>.<ホスト名> RailsEnv development DocumentRoot /var/www/アプリケーション名/public <Directory /var/www/アプリケーション名/public> AuthType Basic AuthUserFile "htpasswdのパス" AuthName "basic認証の名前" AllowOverride all Require valid-user Options -MultiViews </Directory> </VirtualHost>

トップページのアクセスは、development.logでは200 OKが記録されています。

Started GET "/" for <クライアントのIP> at 2017-01-22 13:58:31 +0900 Processing by TopController#index as HTML Rendering <省略> Rendered <省略> <省略> Completed 200 OK in 64ms (Views: 63.4ms | ActiveRecord: 0.0ms)

それ以外のページへのアクセスは、クライアント側は(Not Found)で、development.logは記録がありませんでした。

もともとローカルの仮想環境で開発していて、その時は正常でした。(rails serverでlocalhost:3000のアクセス)
SELinuxを完全に無効にしてみたりもしましたが治りませんでした。

怪しいところ、些細なことでもいいのでアドバイス頂きたいです。

追記

apache conf

# SHTMLに対応していないブラウザ SetEnvIfExpr "!(%{HTTP_ACCEPT} -strcmatch '*application/xhtml+xml*') || %{HTTP_USER_AGENT} =~ m#UP\\.Browser/6\\.2|Nintendo 3DS| NX/1\\.#" LEGACY_BROWSER ServerRoot "/etc/httpd" # #Listen 12.34.56.78:80 Listen 80 # # Example: # LoadModule foo_module modules/mod_foo.so # Include conf.modules.d/*.conf # # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User apache Group apache # # ServerAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. admin@your-domain.com # ServerAdmin <私のメールアドレス> # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # ServerName <このサーバのホスト名>:80 # # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> AllowOverride none Require all denied </Directory> # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html" # # Relax access to content within /var/www. # # <Directory "/var/www"> # AllowOverride None # # Allow open access: # Require all granted # </Directory> # Further relax access to the default document root: <Directory "/var/www"> # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # # Require all granted </Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html </IfModule> # スラッシュで終わるURLを、「index」を追加したURLにリダイレクトする # RedirectMatch permanent ^(.*)/$ $1/index # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <Files ".ht*"> Require all denied </Files> # # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here. # ErrorLog "logs/error_log" # # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn <IfModule log_config_module> # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> # # If you prefer a logfile with access, agent, and referer information # (Combined Logfile Format) you can use the following directive. # CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> # # Redirect: Allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. The client # will make a new request for the document at its new location. # Example: # Redirect permanent /foo http://www.example.com/bar <If "-n %{PATH_INFO}"> # 存在しないディレクトリがURLに含まれていれば、404 Not Found を返す Redirect 404 / </If> # # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. The same rules about trailing "/" apply to ScriptAlias # directives as to Alias. # ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule> # # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz # # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # # AddType text/html .shtml # AddOutputFilter INCLUDES .shtml <If "-n reqenv('LEGACY_BROWSER')"> # XHTMLに対応していなければ AddType text/html .xhtml </If> </IfModule> # # Specify a default charset for all content served; this enables # interpretation of all content as UTF-8 by default. To use the # default browser choice (ISO-8859-1), or to allow the META tags # in HTML content to override this choice, comment out this # directive: # # AddDefaultCharset UTF-8 # content-typeヘッダにcharsetパラメータを付加する AddCharset utf-8 .xhtml .html .css .es .js .txt .json .xml .csv <IfModule mime_magic_module> # # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # MIMEMagicFile conf/magic </IfModule> EnableSendfile on # Supplemental configuration # # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf ServerTokens ProductOnly Header always set x-content-type-options nosniff Header always set x-ua-compatible IE=edge

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

httpd.confに

<If "-n %{PATH_INFO}"> # 存在しないディレクトリがURLに含まれていれば、404 Not Found を返す Redirect 404 / </If>

が記載されていたことが原因でした。。。

投稿2017/01/22 06:48

ponsea

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

以下の通りpassengerのapacheモジュール設定を行ってみてください。

passenger設定ファイルを作成する。

sh

1$ passenger-install-apache2-module --snippet | sudo tee /etc/httpd/conf.d/passenger.conf

passenger設定ファイルのインクルード設定を追加する。

sh

1$ sudo vi /etc/httpd/conf.d/vhost.conf

conf

1Include /etc/httpd/conf.d/passenger.conf 2 3<VirtualHost *:80> 4 ServerName <アプリケーション名>.<ホスト名> 5 RailsEnv development 6 DocumentRoot /var/www/アプリケーション名/public 7 <Directory /var/www/アプリケーション名/public> 8 AuthType Basic 9 AuthUserFile "htpasswdのパス" 10 AuthName "basic認証の名前" 11 AllowOverride all 12 Require valid-user 13 Options -MultiViews 14 </Directory> 15</VirtualHost>

投稿2017/01/22 05:53

tkmtmkt

総合スコア1800

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ponsea

2017/01/22 06:27

試してみましたが、治りませんでした。。。 また、 ブラウザのuriに、存在しないパスを入力してみたところ、正しくRouting Errorの赤いページが表示されるので、Passengerは機能しているのかもしれません。。 ですがRouting ErrorにならないページはNot Foundです。。。
ponsea

2017/01/22 06:45

httpd.confに存在しないパスをNot Foundにする設定を、自身で追加していたことが原因でした。。。 webに上がってるのapacheの初期設定の見本を見よう見まねで写してたことが仇となったようです... 迅速な回答ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問