前言
描述:當(dāng)我配置好全部之后,通過 服務(wù)器 ip 地址訪問,遇到報錯信息:500 Internal Server Error
。
情況說明
前提:我是通過Docker啟動nginx容器,通過-v 綁定數(shù)據(jù)卷,將html文件和nginx.conf通過掛載的方式啟動。
我將vue項目打包放在 html路徑下。通過啟動命令啟動nginx容器,命令如下所示:
docker run -d --privileged=true --name nginx -v /mydata/nginx/html:/usr/share/nginx/html -v /mydata/nginx/nginx.conf:/etc/nginx/nginx.conf -p 80:80 nginx
一、展示配置
1.1 nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
1.2 詳細解釋
location / {
root /usr/share/nginx/html;
/usr/share/nginx/html
:對應(yīng)的路徑應(yīng)該是docker內(nèi)部映射的html所在的文件路徑,而不是主機上的html所在路徑。文章來源:http://www.zghlxwxcb.cn/news/detail-732145.html
總結(jié)
至于為什么會出現(xiàn)標(biāo)題上面的報錯,是因為我把配置文件內(nèi)的 root 對應(yīng)的路徑寫錯了。所以在我排查的過程中,一直覺得很奇怪,明明html路徑也有,容器啟動正常,就是訪問不到?;ㄙM了一些時間。文章來源地址http://www.zghlxwxcb.cn/news/detail-732145.html
- 知識歸納:
- 在這個實驗中,我意識到nginx.conf這個文件針對的是容器內(nèi)部才有效,而不是看著容器外面的路徑。
到了這里,關(guān)于nginx部署vue前端項目,訪問報錯500 Internal Server Error的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!