
기본적으로 정적 파일을 제공하는 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
계속 표시됩니다 . 왜? at 은 다음을 제외하고는 아무것도 표시하지 않습니다.index.html
/usr/share/nginx/html;
index.html
error.log
/var/log/nginx
[notice]: signal process started
답변1
localhost의 서버 블록 내에서 위치 블록을 수정하십시오.
root /var/www/vue-frontend/dist;
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
왜냐하면 당신이 원하는 것이 아니라는 location /var/www/vue-frontend/dist {
뜻 이기 때문입니다 .http://localhost/var/www/vue-frontend/dist/index.html