linux安装Nginx及部署

一、Nginx安装

1.下载nginx

nginx: download

2.将下载安装包放在此目录下

cd /usr/local/soft

3.解压

tar -zxvf nginx-1.26.0.tar.gz

4.切换到 Nginx 解压目录

cd nginx-1.26.0

5.安装需要的支持

yum -y install pcre yum -y install openssl openssl-devel yum -y install gd-devel

6.编译前的配置和依赖检查

./configure --user=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --without-http_rewrite_module

7.编译安装

make install

编译安装完后,在 /usr/local/ 目录下会自动生成一个 nginx 目录,代表安装成功!

执行则启动nginx

cd /usr/local/nginx/sbin ./nginx

注意:如果报错

错信息中出现getpwnam,那就说明获取用户失败,添加用户即可

8.测试

curl http://localhost:80

访问当前localhost地址

注意:

放行80端口

#添加80端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

#重新加载防火墙配置

firewall-cmd --reload

#查询所有开启的端口

netstat -tlnp

阿里云的话要配置安全组

二、Nginx部署项目

1.切到nginx目录的配置文件中

cd /usr/local/nginx/conf

vim nginx.conf

cd /usr/local/nginx/sbin ./nginx -s reload

没问题不用执行

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

2.关联前后端

添加以下内容:让访问/prod-api转发的以下地址(8.148.20.242:8080为后端地址)

location /prod-api/ {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://8.148.20.242:8080/;

 }

重启

cd /usr/local/nginx/sbin

./nginx -s reload

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值