linux安装nginx(linux安装nginx详细步骤)
- 下载源码包。
官网地址:https://nginx.org/download/
- 上传到目录下/usr下
- 安装依赖库
-- 检测是否已经安装依赖
yum list installed | grep "pcre-devel"
-- 如果没有安装依赖,执行
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
安装成功后,执行yum list installed | grep "pcre-devel"检查是否已经安装成功
- 解压安装
-- 解压nginx
tar -zxvf nginx-1.21.3.tar.gz
- 进入到目录中,并执行安装模块
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
- 执行编译命令
-- 编译命令
make
- 执行安装命令
-- 执行安装命令
make install
- 检查nginx的配置文件语法是否正确
-- 进入到目录中
cd /usr/local/nginx/sbin/
-- 检查配置文件是否正确
./nginx -t
9.修改配置文件
为了更方便的测试,所以修改配置文件
# 添加开辟端口代码
server {
listen 6005;
server_name 192.168.8.144;
#charset koi8-r;
#access_log logs/host.access.log main;
gzip on;
gzip_static on; # 靠http_gzip_static_module 靠
gzip_min_length 1k;
gzip_comp_level 4;
gzip_proxied any;
gzip_types text/plain text/xml text/css;
gzip_vary on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
root /usr/mcp/dist;
# 若新增后端路由前缀注意在此处添加(|新增)
location / {
proxy_pass http://127.0.0.1:6688/; #注意/后缀
proxy_connect_timeout 15s;
client_max_body_size 100m;
proxy_send_timeout 15s;
proxy_read_timeout 15s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
}
# 避免端点安全问题
if ($request_uri ~ "/actuator"){
return 403;
}
}
- 启动nginx
-- 启动nginx
./nginx
-- 停止命令
./nginx -s stop
-- 重启命令,重新加载配置
./nginx reload
- 关闭防火墙
-- 查看防火墙
firewall-cmd --state
-- 关闭防火墙
systemctl stop firewalld.service
-- 开启防火墙
systemctl start firewalld.service
-- 检查防火墙开发的端口
firewall-cmd --list-ports
-- 检查端口是否开放
firewall-cmd --query-port 80/tcp
-- 开启防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent
-- 移除端口
firewall-cmd --zone=public --remove-port=9090/tcp --permanent
-- 重启防火墙
firewall-cmd --reload
- 检查端口是否正常开发
完毕。