我一直在试图弄清楚如何将服务器指向我的静态页面,我将其存储在云服务器的某个位置。另外,我使用 NodeJs 作为我的后端。
我的老问题:它不是指向我的 myProjectX index.html 而是指向 Nginx 默认网页“Welcome to Nginx!”。我不明白为什么;/
更新
我的新问题:在我完成这个新配置之后,它将我指向 404 页面,而不是指向我的 index.html
此外,在第 20 行中,当我出于调试目的运行 sudo nginx -t 时,它给出了重复“/”的错误
`nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/default:20 `
这是我的 Nginx 配置文件...
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name www.andii90s.com;
root /home/andy/www/myProjectX/app;
index index.html index.htm;
location / {
proxy_pass http://10.137.10.140:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location / {
#Line 20
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/andy/www/myProjectX/app;
}
}
最佳答案
引用此博客 http://caffeinecodes.blogspot.in/2017/02/nginx-settings.html
server {
listen 80;
server_name test.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /Users/Afxal/workspace/test_project/static/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8000;
}
}
关于node.js - 如何设置nginx配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34278909/