这是我的配置文件
$ cat /etc/nginx/nginx.conf
...
http {
...
# service是我在http里增加的部分
server {
listen 80; # nginx监听的端口
server_name 127.0.0.1; ##?
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
location / {
root /home/ubi/web_admin/; # 这是编译好的web项目存放路径,包含index.html文件
index index.html index.htm;
}
# 前端web的/dev-api路径会转发到http://192.168.10.34:6991/api;
location /dev-api{
proxy_pass http://192.168.10.34:6991/api;
}
}
...
}
...
在网上查了很多方法都无法解决:无法显示index.html页面,只显示welcome to nginx页面。
于是我试了把监听的端口改为8080,查看端口8080是否被占用,没有就修改nginx配置文件如下:
# netstat -nap | grep 8080
# vim /etc/nginx/nginx.conf
...
http {
...
server {
...
listen 8080; # nginx监听的端口
...
}
...
}
...
测试修改后的配置文件是否有语法错误
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重启nginx
# systemctl reload nginx
测试是否能显示index.html页面:在浏览器输入地址:http://nginx服务的ip:8080,成功显示