Linux,  网络相关

centos7编译安装nginx

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

yum clean all
yum makecache

yum install -y wget unzip
wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
tar zxf openssl-1.1.1c.tar.gz
wget https://www.zlib.net/fossils/zlib-1.2.11.tar.gz
tar zxf zlib-1.2.11.tar.gz

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.43.zip
unzip pcre-8.43.zip

wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar zxf nginx-1.16.0.tar.gz
cd nginx-1.16.0

yum install -y gcc gcc-c++ make perl

./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/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/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-openssl=../openssl \
--with-pcre=../pcre-8.43 \
--with-zlib=../zlib-1.2.11 \
--with-http_secure_link_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_addition_module \
--with-cc-opt=-O3 \
--with-http_gunzip_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-file-aio \
--with-http_sub_module \
--with-http_dav_module \
--with-http_mp4_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' \
--with-pcre \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi
make && make install

groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M

cat > /etc/nginx/nginx.conf << EOF
user  nginx nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 204800;

events {
    use epoll;
    worker_connections  204800;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

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

    access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;

include /etc/nginx/conf.d/*.conf;
}
EOF

mkdir /etc/nginx/conf.d

cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target
EOF

留言