nginx-1.12.0版本(编译安装)-自定义安装路径
admin
2023-03-17 21:21:19
0

nginx-1.12.0版本(编译安装)-自定义安装路径

安装路径:/application/nginx-1.12.0

1.前期准备

安装编译需要的gccgcc-c++

yum install -y gcc gcc-c++

nginx依赖

pcre-developenssl-develzlib-devel

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

创建用户nginx,以该用户的身份执行nginx

useradd -s /bin/false -M nginx

下载nginx源码包并解压到当前目录

cd /tools
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxf nginx-1.12.0.tar.gz

 

2.nginx编译安装

生成Makefile文件

cd nginx-1.12.0
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.12.0/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

编译源代码并安装

make && make install

 

3.后期结尾

给nginx-1.12.0创建软链接去掉末尾的版本号

ln -s /application/nginx-1.12.0/ /application/nginx

添加环境变量

创建nginx命令软链接到环境变量

ln -s /application/nginx/sbin/* /usr/local/sbin/

 

4.配置nginx开启php支持

在server段中开启php支持

cd /application/nginx
vim conf/nginx.conf


找到如下内容,删除注释字符,并将倒数第二行的 /scripts 替换为 $document_root

修改前

#location ~ \.php$ {

#    root           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

修改后

location ~ \.php$ {

root           html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

该段代码在server中的位置:

server {

    listen       80;

    server_name  localhost;

    location / {

        root   html;

        index  index.php index.html index.htm;

    }

    location ~ \.php$ {

    root           html;

    fastcgi_pass   127.0.0.1:9000;

    fastcgi_index  index.php;

    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    include        fastcgi_params;

    }

}

注意:location ~ \.php$ {}块中root的值和location / {}块中root的值需要一致

 

5.常用命令

检查配置文件

nginx -t

指定其他配置文件启动nginx

nginx -c /application/nginx/conf/nginx.conf.bak

启动nginx

nginx

停止nginx

nginx -s stop

重启nginx

nginx -s reload

参数解释

-s stop 快速停止nginx

-s quit 平滑停止nginx

-s reopen 重新打开日志文件

-s reload 平滑重载所有配置

 

6.目录介绍

 [root@www nginx]# tree
.
├── conf  #配置文件目录
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default  #fastcgi *配合php
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types  #mime 媒体类型
│   ├── mime.types.default
│   ├── nginx.conf  #nginx主配置文件
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html  #默认站点目录
│   ├── 50x.html
│   └── index.html
├── logs  #访问日志、错误日志、pid文件目录
│   ├── access.log  #访问日志
│   ├── error.log  #错误日志
│   └── nginx.pid  #pid文件
└── sbin  #命令目录
└── nginx  #nginx命令文件


 


相关内容

热门资讯

浏阳烟花厂爆炸事故是如何发生的... 2026年5月4日下午,湖南长沙浏阳市华盛烟花制造燃放有限公司车间发生爆炸,造成重大人员伤亡,湖南省...
新质生产力企业组团入琼 加速布... 海口5月9日电 (记者 符宇群)“我们希望将公司海洋具身智能技术,与海南得天独厚的海域资源进行深度场...
碳讨|AI涌入电力系统:谁在积... 当新能源装机不断逼近火电,“人工智能+电力”正从概念走向现实。 五大发电集团年报显示,清洁能源装机仍...
继德国后,特朗普瞄准意大利 新华社罗马5月9日电(记者王奕涵 刁泽) 据意大利媒体9日报道,美国总统特朗普接受意《晚邮报》电话采...
看人下菜碟,中国绝不当冤大头 2026年世界杯开赛在即,国际足联(FIFA)却向中国“狮子大开口”,要求支付巨额转播费用。国际足联...
特朗普还有一场硬仗 新华社北京5月9日电 美国民主、共和两党当前正推动有利本党的国会选区重划,并为此大打官司。弗吉尼亚州...
美国佛州发生疑似船只爆炸事故,... 当地时间5月9日,总台记者获悉,美国佛罗里达州迈阿密海滩附近一处热门水上聚会区域发生疑似船只爆炸事故...
【快看】涉及手机、电脑、电视等... 工业和信息化部、商务部、市场监管总局等部门近日联合启动实施《人工智能终端智能化分级》系列国家标准。 ...
中锂电取得锂电池安全保护装置专... 国家知识产权局信息显示,浙江中锂电科技有限公司取得一项名为“一种锂电池安全保护装置”的专利,授权公告...
奥特曼“官宣” OpenAI ... 文 | AI唱反调 今早,奥特曼发布了一条 X,几乎坐实了近半个月来的传闻。 X正文只有三个词:“...