nginx安装配置

# 创建nginx用户和用户组:$ groupadd -f nginx

$ useradd -g nginx nginx

# 配置好系统yum源,安装如下依赖包:

$ yum install gcc pcre-devel openssl-devel

# 下载上传 nginx-1.20.2.tar.gz至服务器,解压文件包

命令如下:$ tar -xvf  nginx-1.20.2.tar.gz  

# 安装编译nginx命令如下:

$ ./configure --group=nginx --user=nginx --prefix=/app/nginx --conf-path=/app/nginx/etc/nginx/nginx.conf --error-log-path=/app/nginx/logs/error.log --http-log-path=/app/nginx/logs/access.log --http-client-body-temp-path=/app/nginx/tmp/nginx/client_body --http-proxy-temp-path=/app/nginx/tmp/nginx/proxy --http-fastcgi-temp-path=/app/nginx/tmp/nginx/fastcgi --pid-path=/app/nginx/logs/nginx.pid --lock-path=/app/nginx/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre

$ make && make install

# 配置nginx.conf,修改如下内容

       location / {

             root /app/nginx/html/zabbix;

             try_files $uri $uri/ /index.php?query_string;

             index index.php index.html index.htm;

        }

        location ~ \.php$ {

            root   /app/nginx/html/zabbix;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

# 配置nginx开机自启动服务

# 1、创建/usr/lib/systemd/system/nginx.service文件,

输入如下内容:

$ vi /usr/lib/systemd/system/nginx.service

[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/app/nginx/logs/nginx.pid

ExecStartPre=/app/nginx/sbin/nginx -t -c /app/nginx/etc/nginx/nginx.conf

ExecStart=/app/nginx/sbin/nginx -c /app/nginx/etc/nginx/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true

[Install]

WantedBy=multi-user.target

2、重载系统服务:$ systemctl daemon-reload 

3、设置开机启动:$ mkdir -p /app/nginx/tmp/nginx/client_body

$ systemctl enable nginx.service 

$ systemctl start nginx.service

这边我直接配置的环境变量启动及重载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值