(一)LNMP环境源码编译安装zabbix-4.0.x——编译安装Nginx

版权声明:欢迎转载与交流。https://blog.csdn.net/one2more/article/details/115282343

1、软件包列表

序号软件包名称下载地址
01pcre-8.44.tar.gzhttps://sourceforge.net/projects/pcre/files/pcre/
02openssl-1.1.1j.tar.gzhttps://www.openssl.org/source/
03zlib-1.2.11.tar.gzhttp://www.zlib.net/
04nginx-1.18.0.tar.gzhttp://nginx.org/en/download.html

2、安装相关依赖包

yum install -y gcc gcc-c++ make wget lrzsz unzip net-tools

3、解压相关软件包

tar -xzf /usr/local/src/pcre-8.44.tar.gz -C /usr/local/src
tar -zxf /usr/local/src/openssl-1.1.1j.tar.gz -C /usr/local/src
tar -xzf /usr/local/src/zlib-1.2.11.tar.gz -C /usr/local/src
tar -xzf /usr/local/src/nginx-1.18.0.tar.gz -C /usr/local/src

4、编译安装Nginx

# 创建nginx用户
useradd  -M nginx -s /sbin/nologin

# ./configure预编译
cd /usr/local/src/nginx-1.18.0/
./configure --user=nginx --group=nginx \
	--prefix=/opt/nginx \
	--error-log-path=/opt/nginx/logs/error.log \
	--http-log-path=/opt/nginx/logs/access.log \
	--with-pcre=/usr/local/src/pcre-8.44 \
	--with-openssl=/usr/local/src/openssl-1.1.1j \
	--with-zlib=/usr/local/src/zlib-1.2.11 \
	--with-stream \
	--with-stream_ssl_module \
	--with-mail \
	--with-mail_ssl_module \
	--with-file-aio \
	--with-http_dav_module \
	--with-http_flv_module \
	--with-http_mp4_module \
	--with-http_gunzip_module \
	--with-http_stub_status_module \
	--with-http_addition_module \
	--with-http_sub_module \
	--with-http_ssl_module \
	--with-http_v2_module

# 编译&&编译安装
make && make install

5、配置Nginx支持PHP

# 创建单独的配置文件存放目录
mkdir /opt/nginx/conf.d

# 配置Nginx引用单独的配置文件
sed -i '/http {/a\    include /opt/nginx/conf.d/*.conf;' /opt/nginx/conf/nginx.conf

# 编写nginx_php.conf
cat > /opt/nginx/conf.d/nginx_php.conf <<-EOF
server {
    listen       8088;
    server_name  localhost;
    #charset koi8-r;
    gzip  on;
    access_log  logs/php_access.log;
    error_log  logs/php_error.log;
    #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   html;
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
            root           html/zabbix;
            index          index.php;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts\$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;
            include        fastcgi_params;
        }
        
    location / {
    		root			html/zabbix;
    		index			index.php;
    }
}
EOF

# PHP探针/测试页面
 echo "<?php phpinfo(); ?>" > /opt/nginx/html/index.php

# 启动Nginx
/opt/nginx/sbin/nginx

6、Nginx踩坑记录

    Nginx访问PHP页面报错“FastCGI sent in stderr: “Primary script unknown””
Nginx访问PHP页面报错
    解决办法:

将nginx 网站配置文件*.conf中的fastcgi_param参数按照如下格式修改:
fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
修改为
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

参考文章: http://www.shuchengxian.com/article/657.html.


  用文字分享技术,记录成长! 持续更新中! 欢迎留言、评论交流!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值