前提・実現したいこと
Nginxでバーチャルホストの設定をしても思うように動かなかったので、質問させて頂きます。
下のような感じにしたいです。
http://suzubot.tk または http://www.suzubot.tk/ にアクセスされたら/var/www/home/
の中のファイルを返す- http://test.suzubot.tk にアクセスされたら
/var/www/test/
の中のファイルを返す
発生している問題・エラーメッセージ
http://suzubot.tk/ にアクセスすると、下の画面が表示され、
http://www.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/ のほうは直りました!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/02/28 12:53
2021/02/28 13:30 編集
2021/02/28 21:58