Nginx版本:1.17.9
1、安装依赖
#gcc安装
yum -y install gcc-c++
#pcre安装
yum -y install pcre*
#zlib安装
yum -y install zlib*
#OpenSSL安装(Https必备)
yum -y install openssl*
2、下载并解压
wget -c https://nginx.org/download/nginx-1.17.9.tar.gz
tar zxvf nginx-1.17.9.tar.gz
3、进入目录编译安装
#执行命令
#prefix= 指向安装目录(编译安装)
#conf-path= 指向配置文件(nginx.conf)
#error-log-path= 指向错误日志目录
#pid-path= 指向pid文件(nginx.pid)
#http-log-path= 设定access log路径
#with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
#with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
#with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
./configure --prefix=/usr/local/tool/nginx-1.17.9 --conf-path=/usr/local/tool/nginx-1.17.9/nginx.conf --error-log-path=/usr/local/tool/nginx-1.17.9/logs/error.log --pid-path=/usr/local/tool/nginx-1.17.9/logs/nginx.pid --http-log-path=/usr/local/tool/nginx-1.17.9/logs/access.log --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module
make && make install
#启动nginx
cd /usr/local/tool/nginx-1.17.9/sbin
./nginx
#查看nginx进程
ps -ef | grep nginx
设置开机自动启动
vim /etc/init.d/nginx
下面的nginx文件内容标红的地方需要修改
- nginx="/usr/local/tool/nginx-1.17.9/sbin/nginx" //修改成nginx执行程序的路径。
- NGINX_CONF_FILE="/usr/local/tool/ngi

本文介绍了如何在Linux服务器上配置Nginx,使得不同子域名可以指向不同的项目。主要步骤包括安装依赖、下载解压Nginx、编译安装以及设置开机启动。通过修改nginx.conf文件,设置监听端口、项目域名、根目录及反向代理,实现多项目部署。每个项目只需复制一份server块配置即可。
最低0.47元/天 解锁文章
380

被折叠的 条评论
为什么被折叠?



