nginx环境部署

目录

一、yum安装

二、源码安装

三、测试结果


一、yum安装

1、先查找本地yum源上有没有nginx包

yum list | grep nginx

2、rpm安装

rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.2-1.el7_4.ngx.x86_64.rpm

3、查看安装是否成功

rpm -pa | grep nginx

4、yum安装并查看是否安装成功

yum install nginx
rpm -qa | grep nginx

5、测试启动

systemctl start nginx

注意:如果机子上有安装过apache服务器,记得关闭httpd服务

二、源码安装

1、官网下载安装包并解压

源码包获取: http://nginx.org/download/
tar xf nginx-1.22.0.tar.gz -C /usr/local/src/
2、创建用户id及用户组
id nginx
groupadd -r nginx
grep nginx /etc/group
useradd nginx -u 982 -r -g 982 -c "nginx user" -s /sbin/nologin  # 此处根据实际情况填写。

3、安装基本环境并且进行检查然后完善环境

yum install gcc gcc-c++ make -y
nginx -V # 该命令可以知道需要配置的文件目录和帮助检查等
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module  # 检查依赖和缺哪些开发环境
yum install pcre-devel
yum install openssl-devel
make && make install

4、提供SysV init脚本

cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

5、重启

systemctl daemon-reload
systemctl start ngnix
systemctl status ngnix
netstat -lnupt | grep 80 # 查看80端口是否开启

三、测试结果

nginx环境部署_第1张图片

你可能感兴趣的:(nginx,服务器,运维)