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

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

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

HTTP(Hypertext Transfer Protocol)とはweb上でHTML等のコンテンツを交換するために使われるアプリケーション層の通信プロトコルです。

nginx

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

Q&A

解決済

1回答

1397閲覧

Nginxでバーチャルホストの設定がうまくできない(ラズパイ)

Takkun053

総合スコア19

HTTP

HTTP(Hypertext Transfer Protocol)とはweb上でHTML等のコンテンツを交換するために使われるアプリケーション層の通信プロトコルです。

nginx

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

0グッド

0クリップ

投稿2021/02/28 11:08

編集2021/02/28 12:55

前提・実現したいこと

Nginxでバーチャルホストの設定をしても思うように動かなかったので、質問させて頂きます。

下のような感じにしたいです。

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

http://suzubot.tk/ にアクセスすると、下の画面が表示され、http://suzubot.tk/

http://www.suzubot.tk/ にアクセスすると、下の画面が表示され、http://www.suzubot.tk/

http://test.suzubot.tk/ にアクセスすると、下の画面が表示されます。http://test.suzubot.tk/

エラーは出ていません。

該当のソースコード

/etc/nginx/nginx.conf

conf

1user www-data; 2worker_processes auto; 3pid /run/nginx.pid; 4include /etc/nginx/modules-enabled/*.conf; 5 6events { 7 worker_connections 768; 8 # multi_accept on; 9} 10 11http { 12 13 ## 14 # Basic Settings 15 ## 16 17 sendfile on; 18 tcp_nopush on; 19 tcp_nodelay on; 20 keepalive_timeout 65; 21 types_hash_max_size 2048; 22 # server_tokens off; 23 24 # server_names_hash_bucket_size 64; 25 # server_name_in_redirect off; 26 27 include /etc/nginx/mime.types; 28 default_type application/octet-stream; 29 30 ## 31 # SSL Settings 32 ## 33 34 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 35 ssl_prefer_server_ciphers on; 36 37 ## 38 # Logging Settings 39 ## 40 41 access_log /var/log/nginx/access.log; 42 error_log /var/log/nginx/error.log; 43 44 ## 45 # Gzip Settings 46 ## 47 48 gzip on; 49 50 # gzip_vary on; 51 # gzip_proxied any; 52 # gzip_comp_level 6; 53 # gzip_buffers 16 8k; 54 # gzip_http_version 1.1; 55 # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; 56 57 ## 58 # Virtual Host Configs 59 ## 60 61 include /etc/nginx/conf.d/*.conf; 62 include /etc/nginx/sites-enabled/*; 63} 64 65 66#mail { 67# # See sample authentication script at: 68# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript 69# 70# # auth_http localhost/auth.php; 71# # pop3_capabilities "TOP" "USER"; 72# # imap_capabilities "IMAP4rev1" "UIDPLUS"; 73# 74# server { 75# listen localhost:110; 76# protocol pop3; 77# proxy on; 78# } 79# 80# server { 81# listen localhost:143; 82# protocol imap; 83# proxy on; 84# } 85#}

/etc/nginx/sites-enabled/default

## # 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. # https://www.nginx.com/resources/wiki/start/ # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ # https://wiki.debian.org/Nginx/DirectoryStructure # # In most cases, administrators will remove this file from sites-enabled/ and # leave it as reference inside of sites-available where it will continue to be # updated by the nginx packaging team. # # This file will automatically load configuration files provided by other # applications, such as Drupal or Wordpress. These applications will be made # available underneath a path with that package name, such as /drupal8. # # 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/home; # Add index.php to the list if you are using PHP index index.html index.php 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 PHP scripts to FastCGI server # location ~ .php$ { include snippets/fastcgi-php.conf; # With php-fpm (or other unix sockets): fastcgi_pass unix:/run/php/php7.3-fpm.sock; # With php-cgi (or other tcp sockets): #fastcgi_pass 127.0.0.1:9000; } # 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 www.suzubot.tk; # # root /var/www/home; # index index.html index.php; # # location / { # try_files $uri $uri/ =404; # } #}

/etc/nginx/sites-enabled/suzubot.tk.conf

conf

1server { 2 listen 80; 3 listen [::]:80; 4 5 server_name www.suzubot.tk; 6 7 root /var/www/home; 8 index index.html index.php; 9 10 location / { 11 try_files $uri $uri/ =404; 12 } 13} 14 15server { 16 listen 80; 17 listen [::]:80; 18 19 server_name test.suzubot.tk; 20 21 root /var/www/test; 22 index index.html index.php; 23 24 location / { 25 try_files $uri $uri/ =404; 26 } 27}

試したこと

バーチャルホストの設定の書く場所を変えてみましたが、うまくいきませんでした。

補足情報

ラズパイバージョン:

No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 10 (buster) Release: 10 Codename: buster

Nginxバージョン: nginx/1.14.2

@Neko7sora さんのおかげで http://www.suzubot.tk/ のほうは直りました!

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

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

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

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

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

guest

回答1

0

ベストアンサー

このように修正すれば、直るはずです。(!!!!! <--目印)

ソースコード

/etc/nginx/sites-enabled/default

nginx

1 # 2 # Self signed certs generated by the ssl-cert package 3 # Don't use them in a production server! 4 # 5 # include snippets/snakeoil.conf; 6 7 root /var/www/home; 8 9 # Add index.php to the list if you are using PHP 10 index index.html index.php index.htm index.nginx-debian.html; 11 12 server_name _; 13 14 server_name www.suzubot.tk; # <--!!!!!! add server_name www.suzubot.tk 15 16 location / { 17 # First attempt to serve request as file, then 18 # as directory, then fall back to displaying a 404. 19 try_files $uri $uri/ =404; 20 } 21 22 # pass PHP scripts to FastCGI server 23 # 24 location ~ .php$ { 25 include snippets/fastcgi-php.conf; 26 27 # With php-fpm (or other unix sockets): 28 fastcgi_pass unix:/run/php/php7.3-fpm.sock; 29 # With php-cgi (or other tcp sockets): 30 #fastcgi_pass 127.0.0.1:9000; 31 }

/etc/nginx/sites-enabled/suzubot.tk.conf

conf

1# !!!!!!delete 2# server { 3# listen 80; 4# listen [::]:80; 5# 6# server_name www.suzubot.tk; 7# 8# root /var/www/home; 9# index index.html index.php; 10# 11# location / { 12# try_files $uri $uri/ =404; 13# } 14# } 15 16server { 17 listen 80; 18 listen [::]:80; 19 20 server_name test.suzubot.tk; 21 22 root /var/www/test; 23 index index.html index.php; 24 25 location / { 26 try_files $uri $uri/ =404; 27 } 28}

投稿2021/02/28 12:39

Neko7sora

総合スコア19

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

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

Takkun053

2021/02/28 21:58

できました! ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問