
私は基本的に静的ファイルを提供する Vue アプリを提供しようとしています。バックエンドの PHP API サーバーも含まれるシンプルな構成です。
にアクセスするとapi.localhost
(ファイルに追加しましたhosts
)、バックエンドの HTML ページが表示されます。しかし、 にアクセスすると、エラー ページlocalhost
が表示されます。50x
user www-data;
http {
server {
listen 80;
server_name api.localhost;
root /var/www/php-backend/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
server {
listen 80;
server_name localhost;
location /var/www/vue-frontend/dist {
root /;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
events {}
に行くと、 Vue ではなく、内部のページがlocalhost
表示され続けます。なぜでしょうか?では、index.html
/usr/share/nginx/html;
index.html
error.log
/var/log/nginx
[notice]: signal process started
答え1
localhost の server ブロック内の location ブロックを変更してください:
root /var/www/vue-frontend/dist;
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
because は あなたが望んでいることではないことlocation /var/www/vue-frontend/dist {
を意味します
http://localhost/var/www/vue-frontend/dist/index.html
。