如何使用阿里云服务器公网IP访问自己的网页?

您所在的位置:网站首页 服务器上怎么打开网页文件 如何使用阿里云服务器公网IP访问自己的网页?

如何使用阿里云服务器公网IP访问自己的网页?

2024-07-10 12:01:55| 来源: 网络整理| 查看: 265

一.服务器的初步配置 1.配置安全组:

如果你有条件或者有需求注册域名,那么你可以直接在阿里云中申请并且跳过第一步,如果你还不想申请域名,那么也可以通过公网IP访问你的服务器。

首先在云服务器管理控制台左边栏找到网络与安全——安全组在这里插入图片描述 进入后选择配置规则,将安全组规则配置成如下图:在这里插入图片描述具体应用可以参见《阿里云官方文档》:在这里插入图片描述完成配置后即可通过公网ip访问你的服务器了!

2.下载安装Nginx

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。

首先需要通过远程链接到服务器终端在这里插入图片描述 终端下输入sudo apt-get update及sudo apt-get -y install nginx下载Nginx。 此时即可通过公网IP访问储存在/usr/share/nginx/html文件夹中的index.html文件。在浏览器中输入http://公网ip得到如下结果: 在这里插入图片描述访问成功!

3.隐藏错误

此时虽然已经可以通过公网ip访问服务器,但可能存在一个问题:无论如何修改index.html中代码,浏览器中却依然不发生改变,仍然显示为:在这里插入图片描述这个问题的原因在于安装Nginx后未进行配置。 此时我们需要找到nginx.conf配置文件,这个文件一般在/etc/nginx目录下:在这里插入图片描述输入vim nginx.conf进入编辑,将配置文件改为如下:

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }

代码参考自:Nginx(二)------nginx.conf 配置文件(侵删)

此时返回/usr/share/nginx/html目录下,尝试修改index.html文件:在这里插入图片描述访问公网IP:在这里插入图片描述修改成功!

这里做一点说明:当你通过公网IP访问服务器时,修改后的Nginx将会优先找到index.html文件运行。(具体细节参见代码来源)

//update 2020.4.8

//喜欢别忘了点赞呀



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭