下载Nginx
在FinalShell中输入命令:
wget http://nginx.org/download/nginx-1.24.0.tar.gz
配置yum环境
1、解决依赖工具
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2、将上传好的安装包拷贝到/usr目录中
cd
cd /usr
ls
cd local/
pwd
mkdir nginx
cd nginx/
ls
pwd
cp ~/nginx-1.24.0.tar.gz ./
ls
3、解压nginx文件
tar -xzvf nginx-1.24.0.tar.gz
ls
4、进入nginx目录
cd nginx-1.24.0
5、安装
./configure \
然后依次键入以下内容:
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_stub_status_module
6、执行编译并安装
make
make install
7、验证是否安装成功
cd /usr/local/nginx
ll
8、启动nginx
cd sbin
./nginx
启动后查看是否有nginx:
ps -aux | grep nginx
9、开放防火墙端口
systemctl start firewalld
firewall-cmd --zone=public --add-port=8080/tcp --permanent
如果输入上一步命令出现:
FirewallD is not running
则需要先在阿里云服务器上设置开放端口:
第一步:进入云服务器ECS
第二步:
第三步:
第四步:
第五步:
完成以上步骤再次输入:
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd –reload
若两句的执行结果均为success,至此Linux外网访问端口已开启。
注意:
Linux打开端口命令每一个打开的端口,都需要有相应的监听程序才可以
- 查看端口监听程序
netstat -ntlp
- 测试
1、安装nc
切换到root用户:
yum install -y nc
2、监听端口(当客户端链接之后关闭)
nc -lp 端口 &
3、本地使用 telnat 访问
telnat 服务器ip地址 端口
在网页中远程访问Nginx
在地址栏输入自己的IP地址运行出现以下界面则配置成功:
至此,所有配置完成。