从源码安装nginx的步骤和常见问题解决
以centos7为例
wget https://nginx.org/download/nginx-1.20.2.tar.gz
./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio --with-http_sub_module --with-http_gzip_static_module
问题,无pcre
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
yum -y install pcre-devel
问题:无openssl
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl= option.
http://nginx.org/en/docs/configure.html
cat -> /usr/lib/systemd/system/nginx.service<<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
启动问题
nginx: [emerg] getpwnam("nginx") failed
原因:没有nginx这个用户
解决办法:
办法1 新建nginx用户 给予合适权限
办法2 修改 nginx.conf文件,用root启动
共有 0 条评论