一、Nginx安装
1.下载nginx
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