Linux安装nginx完整步骤

一、安装依赖(安装过的跳过)

yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel gd-devel

二、下载nginx稳定版

wget http://nginx.org/download/nginx-1.16.1.tar.gz

三、解压–编译–安装

解压

tar -zxvf nginx-1.16.1.tar.gz

进入解压目录

cd /opt/nginx-1.16.1

编译

# 安装到指定目录并配置用户(prefix指定的目录需要创建一个新的文件) 
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_addition_module  --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module

执行报错不用理会,一般是模块没有对应的安装依赖 必要的都已经安装了

编译并安装(如没有权限,可使用sudo以root用户权限安装)

第一步
make
第二步
make install

这时候进入/usr/local/nginx路径,就能看到生成这些文件,启动文件和配置文件都在这里

 

 

五、nginx服务的启动操作

# 检查默认配置文件
./sbin/nginx -t -c ./conf/nginx.conf
# 启动
./sbin/nginx -c ./conf/nginx.conf
# 停止
./sbin/nginx -s stop
# 或
./sbin/nginx -s quit
# 或
kill -9 <Nginx and works PID

Linux服务器上配置Nginx服务开机自启动

# 直接编辑/etc/rc.local文件,文件内容最底下添加启动命令

[root@hecs-223575 ~]# vim /etc/rc.local 
# 最后追加内容 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf &

 

posted @ 2023-04-07 15:01  红豆奶茶+红豆  阅读(141)  评论(0)    收藏  举报