您所在的位置:首页 - Linux - 正文Linux

Nginx nginx-1.19.10 源码与腾讯云dnf 安装

萧何-Vincent 萧何-Vincent 2021-09-08 【Linux】 1177人已围观

一、下载Nginx源文件
进入nginx官网下载nginx的稳定版本,我下载的是1.10.0。
下载:wget http://nginx.org/download/nginx-1.19.10.tar.gz 解压:tar -zxvf nginx-1.19.10.tar.gz

二、检查安装依赖项,执行下面的命令安装nginx的依赖库:

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel


三、安装前先创建好www 用户和组

groupadd www
useradd -g www www
chsh -s /sbin/nologin www
cat /etc/passwd|grep www


四、配置Nginx安装选项
这里只配置安装到/bin目录下,直接可以使用nginx 命令启动 无需添加路径启动Nginx 进程,cd nginx安装目录,执行如下命令:

 ./configure  --prefix=/usr/local/nginx  --sbin-path=/usr/bin/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-threads --user=www --group=www


五、编译并安装

make && make install


六、启动、停止、重启

# 1.启动nginx

shell> nginx


# 可通过

ps -ef | grep nginx

查看nginx是否已启动成功


# 2.停止nginx

shell> nginx -s stop


# 3. 重新启动

shell> nginx -s reload


查看Nginx 进程

ps -ef|grep nginx


查看防火墙Nginx端口是否开启

firewall-cmd --zone=public --list-ports


添加防火墙Nginx端口

firewall-cmd --zone=public --add-port=9000/tcp --permanent (--permanent永久生效,没有此参数重启后失效)

检查是否开启开机启动

chkconfig --list
chkconfig --add nginx
chkconfig nginx on


六、配置nginx开机启动
将/usr/bin/nginx命令添加到/etc/rc.d/rc.local文件中,rc.local文件会在系统启动的时候执行。但CentOS7建议将开机启动服务写成服务描述文件添加到系统服务中,所以rc.local默认没有执行权限,需要给它添加执行权限。

shell> vim /etc/rc.d/rc.local


# 添加如下参数

/usr/bin/nginx
shell> chmod +x /etc/rc.d/rc.local


扩展知识

腾讯云Centos 7.6-8.2 安装最新版Nginx 1.23.2如下:


1.执行以下命令,在 /etc/yum.repos.d/ 下创建 nginx.repo 文件。

vi /etc/yum.repos.d/nginx.repo


2.按 i 切换至编辑模式,写入以下内容。

[nginx] 
name = nginx repo 
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ 
gpgcheck = 0 
enabled = 1

3.按 Esc,输入 :wq,保存文件并返回。

4.执行以下命令,安装 nginx。

  yum install -y nginx


5.执行以下命令,打开 default.conf 文件。

vim /etc/nginx/conf.d/default.conf


6.按 i 切换至编辑模式,编辑 default.conf 文件。

7.找到 server{...},并将 server 大括号中相应的配置信息替换为如下内容。用于取消对 IPv6 地址的监听,同时配置 Nginx,实现与 PHP 的联动。

 (或者直接nginx 目录下新建vhosts 文件夹,nginx.conf  inculde vhosts 里conf 文件 include /etc/nginx/vhosts/*.conf;)

server {
    listen       80;
    root   /usr/share/nginx/html;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    #
    location / {
          index index.php index.html index.htm;
    }
    #error_page  404              /404.html;
    #redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
    #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
}


8.按 Esc,输入 :wq,保存文件并返回。

9.执行以下命令启动 Nginx

systemctl start nginx


10.执行以下命令,设置 Nginx 为开机自启动。

 systemctl enable nginx


显示如下,则说明 Nginx 安装配置成功。

nginx.png


Tags: Nginx

文章评论 (暂无评论,1177人围观)

我的名片

网名:Vincent

职业:IT

现居:SZ

Email:53126692@qq.com

站长寄语:技术分享,支持原创!

站点信息

  • 文章总数:65
  • 页面总数:1
  • 分类总数:5
  • 标签总数:12
  • 评论总数:24
  • 浏览总数:82970
取消
微信二维码
支付宝二维码

目录[+]