Ubuntu16.04 源码安装nginx并修改Server名

xiaoxiao2021-02-28  124

我自己在Ubuntu的docker容器中创建成功

Dockerfile:

# nginx source installs test FROM ubuntu COPY . /root RUN apt-get update && \ apt-get -y upgrade && \ apt-get -y install pcre* zlib* openssl gcc libpcre3 libpcre3-dev libssl-dev net-tools vim make && \ tar -zxvf nginx-1.12.1.tar.gz EXPOSE 80 CMD /bin/bash docker build -t lsx/nginx_test .

#创建docker容器

docker run -itd --name "nginx_source" -p 20020:80 lsx/nginx_test

#映射到20020端口

运行容器后进入容器,对 core/nginx.h

#define NGINX_VERSION      修改 #define NGINX_VER          修改 NGINX_VERSION

http/ngx_http_special_response.c

static u_char ngx_http_error_tail[] = "<hr><center>修改</center>" CRLF

http/ngx_http_header_filter_module.c

static u_char ngx_http_server_string[] = "Server: 修改" CRLF; static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;

之后进行安装:

useradd nginx -s /usr/sbin/nologin

./configure --prefix=/usr/local/nginx-1 --user=nginx --group=nginx --with-http_ssl_module

#上面的模块还可以再加

make && make install

安装完之后,运行nginx:/usr/local/nginx-1/sbin/nginx

之后查看本机的20020端口就可以看到nginx的运行了。

停止nginx:/usr/local/nginx-1/sbin/nginx -s stop

备注:

rpm -qf file 对应 dpkg-query -S file rpm -ql package 对应 dpkg-query -L package

转载请注明原文地址: https://www.6miu.com/read-33734.html

最新回复(0)