版权声明:欢迎转载与交流。https://blog.csdn.net/one2more/article/details/115282343
(一)LNMP环境源码编译安装zabbix-4.0.x——编译安装Nginx
1、软件包列表
序号 | 软件包名称 | 下载地址 |
---|---|---|
01 | pcre-8.44.tar.gz | https://sourceforge.net/projects/pcre/files/pcre/ |
02 | openssl-1.1.1j.tar.gz | https://www.openssl.org/source/ |
03 | zlib-1.2.11.tar.gz | http://www.zlib.net/ |
04 | nginx-1.18.0.tar.gz | http://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 网站配置文件*.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.
用文字分享技术,记录成长! 持续更新中! 欢迎留言、评论交流!