Nginx指定prefix路径启动
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"';
- 解决办法:要么两个都注释掉,要么都打开