nginx指定prefix路径启动

25 篇文章 0 订阅

1、需求

  • 两个环境(最好是相同的环境,不同的环境如:1个是centos,一个是ubuntu没测试过)
  • 环境1上编译好nginx,直接打包放到环境2上运行

需求不同,环境1上编译的位置在/usr/local/nginx
环境2上需要放到/data/nginx目录下

在这里插入图片描述

2、问题

  • 环境2上启动导致nginx一直找默认编译的/usr/local/nginx目录

这样肯定是不行滴

3、解决办法

在启动时设置nginx的默认位置

[root@node1 nginx]# sbin/nginx -h
nginx version: nginx/1.22.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
             [-e filename] [-c filename] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -e filename   : set error log file (default: logs/error.log)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

查看nginx的帮助文档可以看到有个-p prefix : set prefix path (default: /usr/local/nginx/) 能够让我们避免从新编译直接指定nginx的安装位置很大程度解决了二次编译的麻烦


[root@node1 nginx]# sbin/nginx --prefix=/data/nginx -t
nginx: invalid option: "-"
[root@node1 nginx]# sbin/nginx -p /data/nginx -t        
nginx: [emerg] unknown log format "main" in /data/nginx/conf/nginx.conf:25
nginx: configuration file /data/nginx/conf/nginx.conf test failed

在这里插入图片描述

4、解决:[emerg] unknown log format “main”

查看配置文件发现是由于我开启了配置access_log logs/access.log main;但是却没有开启

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

在这里插入图片描述

  • 解决办法:要么两个都注释掉,要么都打开
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值