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

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

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

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Q&A

解決済

2回答

1612閲覧

サーバー移行(Windows>Ubuntu)のnginx設定

wangzj

総合スコア53

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

0グッド

0クリップ

投稿2021/01/01 13:48

編集2021/01/03 10:47

前提・実現したいこと

Windowsサーバーで動いてるシステムをUbuntuに移行したい
手順:
1.Ubuntu 18.04 LTS に OpenJDK 9 をインストールする
2.Apache Tomcat 9 を Ubuntu 18.04 LTS にインストールする
3.MySQLサーバとクライアントツールのインストール
4.Redis を Ubuntu 18.04 LTS にインストールする
5.Ubuntu 18.04にNginxをインストールする
6.データベース復元
7.既存ソース配置

発生している問題・エラーメッセージ

Welcome to nginx! すべての設定は終わりましたが、 なぜか↑ページのままで、画面が変わらない

該当のソースコード

/etc/nginx/nginx.conf設定ファイル

user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; client_max_body_size 500M; keepalive_timeout 65; gzip on; include /etc/nginx/conf.d/*.conf; #wrs server { listen 80; server_name xxxx.japaneast.cloudapp.azure.com; return 301 https://$host$request_uri; } # HTTPS server server { listen 443; server_name xxxx.japaneast.cloudapp.azure.com; index index.html; root /usr/share/nginx/dist; location ^~/pms_web/ { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ^~/pms-pic/ { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { try_files $uri $uri/ @router; index index.html; } location @router { rewrite ^.*$ /index.html last; } } }

/opt/apache-tomcat-9.0.38/conf/server.xml
このファイルの最後に、<Context reloadable="false" docBase="/usr/upload" path="/pms-pic"/>を追加しただけです。

<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Note: A "Server" is not itself a "Container", so you may not define subcomponents such as "Valves" at this level. Documentation at /docs/config/server.html --> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <!-- Security listener. Documentation at /docs/config/listeners.html <Listener className="org.apache.catalina.security.SecurityListener" /> --> <!--APR library loader. Documentation at /docs/apr.html --> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <!-- Prevent memory leaks due to use of particular java/javax APIs--> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <!-- Global JNDI resources Documentation at /docs/jndi-resources-howto.html --> <GlobalNamingResources> <!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <!--For clustering, please take a look at documentation at: /docs/cluster-howto.html (simple how to) /docs/config/cluster.html (reference documentation) --> <!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> --> <!-- Use the LockOutRealm to prevent attempts to guess user passwords via a brute-force attack --> <Realm className="org.apache.catalina.realm.LockOutRealm"> <!-- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase". Any edits that are performed against this UserDatabase are immediately available for use by the Realm. --> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" /> <Context reloadable="false" docBase="/usr/upload" path="/pms-pic"/> </Host> </Engine> </Service> </Server>

試したこと

・JAVA_HOME設定追加
・nginx再起動

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

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

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

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

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

guest

回答2

0

tomcatの事は分からないけれどtomcatへリクエストを流す処理がnginx上でされていません。
nginxのconfを編集し、tomcatサーバーへのproxyを設定しましょう

仕様・設計を明確にしてから移行作業をしましょう。

後出し情報が多く、例えばどういう形でアクセスさせて表示させたいのかも不明瞭なのが質問者の現在の状態です。
仕様が明確になったら丁寧に移行手順書を作り、社内の仲間達とレビューしましょう。

投稿2021/01/01 14:16

編集2021/01/02 11:29
hentaiman

総合スコア6426

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

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

wangzj

2021/01/02 06:54

ご回答ありがとうございます。 proxy_passなどの設定を追加しましたが、現象が変わりません。
hentaiman

2021/01/02 07:40

tomcat側のプロトコルとlocationの設定合ってます?質問内容からはnginxの設定しか分からないのでそのぐらいしか訊いてあげられませんが
hentaiman

2021/01/02 08:39

それだけだと分かりませんが、locationは合ってますか? 質問の意味が分からなければ実際にアクセスする時のURLを記載してくれればOKです
hentaiman

2021/01/02 09:17

locationが合ってませんね その場合は以下のlocationに対してproxy_passが必要です。 location / { try_files $uri $uri/ @router; index index.html; }
wangzj

2021/01/02 09:37 編集

location を下記のように、変更しました location / { proxy_pass http://127.0.0.1:8080; try_files $uri $uri/ @router; index index.html; } アクセスURL:https://xxxx.japaneast.cloudapp.azure.com >>> xxxx.japaneast.cloudapp.azure.com から無効な応答が送信されました。 Windows ネットワーク診断ツールを実行してみてください。 ERR_SSL_PROTOCOL_ERROR アクセスURL:http://20.xx.104.xx/ Welcome to nginx!ページ ちなみに、nginx.confは動いてるWindows Serverを参照して作りました。
hentaiman

2021/01/02 09:38

そのエラーはproxyとは関係無い問題です。 本当に同じconf設定でwindowsで動いていたのなら移行漏れがあるはずです。 漏れなく移行しているのに前のサーバーで動作していたというのなら、前の環境が何かしらおかしかったのでしょう。 少なくとも設定に関してはひとつ前の自分のコメントで(tomcat側の設定が不明とは言え)ほぼ確実に正解なので、本質問の範囲外の不具合です。 まずは移行漏れが無いかの確認をしましょう。
wangzj

2021/01/02 09:50 編集

現状Windows Serverで動いてるWEBシステムは フロント>nginx バックエンド>Apache Tomcat フロントのjsより、location ^~/pms_web/でバックエンドを呼び出す になっています。 Ubuntuのtomcat側の設定にも問題があるかもしれませんが、 「フロント>nginx」に問題がなければ、index.htmlを表示されるはずです。
hentaiman

2021/01/02 09:56

jsからそのURL呼び出すとか質問に書いて無い事なんて分からんし・・・ 「はず」はいいのでとりあえず設定など情報全部晒して下さい。 質問に提示されていた内容を解決する為の回答をしただけなので、見えていない部分は何も分かりません。
wangzj

2021/01/02 10:45

設定ファイル/opt/apache-tomcat-9.0.38/conf/server.xml を追加しました。 それ以外、特に修正したことがないです。
hentaiman

2021/01/02 11:26

設定ファイルだけでなく、やりたい事も分からないと。 少なくとも最初の時点ではproxy_passを書けば良かった、 しかし後出し情報によって「location /」にproxy_passを書く必要があると分かった、 かと思いきやindex.htmlは表示したいとの事なので「location /」にproxy_passを書いてはいけない 情報が正しくない為、正しい設定が分からない状態です。 SSLエラーは本質問とは別問題です。何度も言いますが元々SSLエラーが出なかったのならそれは移行ミスなので見比べましょう。 都度都度後出しに合わせて確認するのは怠いのでこれで終わりにしますが、「仕様・設計に沿ったproxy_pass」を設定するだけで解決する問題とだけ言っておきます。
wangzj

2021/01/02 16:10

原因が分かりました。 nginxのdefault.confを削除されてなかったので、影響がでてました。
guest

0

自己解決

nginxのdefault.confを削除したら、うまく行きました。
移行にまだ別の問題がありまして、別途起票します。

投稿2021/01/02 16:11

wangzj

総合スコア53

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

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

hentaiman

2021/01/02 16:16

自己解決したという事は自分の回答で教えたProxy_passすら不要だったという事ですね?
wangzj

2021/01/03 01:47

index画面表示までProxy_passが不要です。
hentaiman

2021/01/03 04:47

この質問ではjavaは関係無かった(tomcatの表示が目的ではなかった)という事ですね?
wangzj

2021/01/03 08:50

質問は「発生している問題・エラーメッセージ」の部分となります。 環境構築にすべて完了したのに、なぜドメイン・IPアドレスでアクセスすると、「Welcome to nginx!」ページのままで、画面が変わらないです。 原因はnginxのdefault.confを削除されてなかったので、影響が出てました。 引き続き作業していますが、実はtomcat設定にも問題があると思います。 解決できなかったら、別途質問しようと思います。
hentaiman

2021/01/03 10:16

ではタグからJavaを削除して質問本文からもjavaに関する情報を削除して、nginxが動かないという内容に修正してもらえますか? 少なくとも元の質問文・修正後の質問文ではこの回答で自己解決はありえなく、また正しい回答は自分の回答です。 主に質問文とは無関係な個所が原因で、しかも回答でのやり取り後に自身で回答を書いて自己解決とするのならその解決内容にあった質問文に修正してください。 > 解決できなかったら、別途質問しようと思います。 質問文に書かれていない情報が無い限りは既に正しい解決法を提示しています。なぜか自己解決とされている状態ですが。
hentaiman

2021/01/03 10:20

まあ万が一自己解決としたまま新たに質問するのならその時は要件を明確に記載する事を勧めます。分かる範囲で不要な情報も載せないように。 でないと質問文に対する解決策を教えてもらえるだけで、質問者自身が本来解決したい内容が解決されません。
wangzj

2021/01/03 10:47

紛らしくて、すみません。 指摘通りに、Javaタグを削除しました。 「発生している問題・エラーメッセージ」にも質問を補足しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問