下载nginx压缩包
官网地址:http://nginx.org/en/download.html
将下载的压缩包放进去
安装所需求的环境
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
解压安装包
tar -xvf nginx-1.24.0.tar.gz -C /usr/local
使用cofigure命令创建一个makefile文件
需要进入到解压的nginx-1.24.0目录里面去
./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 \
--with-http_ssl_module \
--with-file-aio \
--with-http_realip_module
进行编译
make && make install
启动nginx
在启动前需要创建文件目录
mkdir /var/temp/nginx -p
cd /usr/local/nginx/sbin
./nginx
查看nginx是否启动
ps -aux | grep nginx
刷新配置文件
./nginx -s reload
关闭防火墙,开启远程访问
[root@131 sbin]# systemctl stop firewalld.service
配置虚拟主机
就是在一台服务器启动多个网站。
如何区分不同的网站:主要有以下两种方式
方式一:端口不同
方式二:域名不同
通过端口区分不同的主机
nginx配置文件的位置:/usr/local/nginx/conf/nginx.conf
原始配置文件的内容如下:
下面测试以下:复制原来的html目录,改名为html-81
cd /usr/local/nginx
cp -r html html-81
修改以下里面的index.html文件,方便区分
vim html-81/index.html
修改完成之后刷新以下配置文件
./nginx -s reload
然后分别访问不同的端口