[记录]阿里云云服务器启动nginx,服务器可以通过localhost:80能够访问,外网无法通过ip访问80端口
阿里云云服务器启动nginx后,服务器可以通过localhost:80能够访问,外网无法通过ip访问80端口问题描述:在阿里云服务器上安装好nginx,配置好前端文件夹路径后,通过ip:80无法响应到网页,前提:阿里云服务器安全组80端口已打开。第一步:检查nginx配置因为后端项目用了springcloud的gateway网关服务,所以不需要处理跨域。nginx.conf配置如下:# For m
·
阿里云云服务器启动nginx后,服务器可以通过localhost:80能够访问,外网无法通过ip访问80端口
问题描述:在阿里云服务器上安装好nginx,配置好前端文件夹路径后,通过ip:80无法响应到网页,前提:阿里云服务器安全组80端口已打开。
第一步:检查nginx配置
因为后端项目用了springcloud的gateway网关服务,所以不需要处理跨域。
nginx.conf配置如下:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name 服务器ip;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /home/taiqu/front_end/; #存放前端打包项目的路径
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
第二步:检查80端口是否占用
netstat -atnlp | grep 80
结果如下,nginx成功监听了80端口。
第三步:在服务器内请求页面
curl http://localhost:80
结果如下:服务器内是能成功访问到,这一步成功说明nginx配置没问题。
如果出现500报错,可能是server中 存放前端打包项目的路径 写错了。
第四步:在服务器内请求ip:80
通过ip访问无响应,查看自己阿里云安全组是否开启80端口,可以看到80端口已开启。
curl http://120.55.93.164:80

第五步:考虑防火墙是否开放80端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
firewall-cmd --permanent --add-port=80/tcp
开放后能成功访问

更多推荐



所有评论(0)