阿里云ECS服务器,域名备案完后网站部署遇到的一路坑。。。
1、新域名访问失败
原因是新的域名需要绑定、解析
查看外网ip
curl ifconfig.me
查看内网IP
ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.22.59.* netmask 255.255.240.* broadcast 172.22.63.*
ether 00:16:3e:10:80:35 txqueuelen 1000 (Ethernet)
RX packets 5188389 bytes 3634034125 (3.3 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4363687 bytes 1706681346 (1.5 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 5809648 bytes 958512549 (914.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5809648 bytes 958512549 (914.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2. 绑定完以后,访问网站仍然失败(内网外网都失败),只是错误变了
vim /var/log/nginx/error.log
更改项目文件权限:
chmod 777 -R test/
然而还是403 Permission denied
解决办法
ps aux | grep "nginx: worker process"
编辑nginx.conf,将nginx.config的user改为和启动用户一致
user nginx 修改为 user root
(由于启动用户和nginx工作用户不一致所致)
#查看nginx的安装目录
whereis nginx
#编辑nginx.config
vim /etc/nginx/nginx.conf
重启nginx
# 查看环境变量中的nginx启动文件的路径
which nginx
# 进入nginx文件所在的文件夹
cd /usr/sbin/
# 检查nginx配置文件是否正确
./nginx -t
# 重启nginx
./nginx -s reload
至此,内网访问成功,然而外网依然是访问不了。。。
3. 关掉防火墙,centos 7 默认安装的防火墙是firewall
systemctl stop firewalld.service 关闭防火墙
安装iptables
- 首先关闭firewall开机启动
systemctl disable firewalld.service
- 确认防火墙是否关掉
# notrunning即表示已关闭
firewall-cmd --state
- 安装iptables
yum install iptables
yum install iptables-services
- 启动iptables
service iptables start 或者 systemctl start iptables
- 设置开机启动iptables
systemctl enable iptables.service
- 编辑防火墙文件
vim /etc/sysconfig/iptables
在其中开启8088、8081端口:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8088 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8081 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
- 设置完之后,重启iptables
service iptables restart 或 systemctl restart iptables
一通设置完后,网站还是不能访问。。。
最后的解决方式:因为主机是阿里云ECS,所以需要在后台安全组里面配置开放内网入8088端口的权限
配置完以后,终于访问成功,太艰难了。。。