linux 之 Nginx 编译安装以及配置https虚拟主机

1、编译安装LNMP,配置自定义404页面,配置访问日志为json格式。

 1.实验环境


[root@chujiapeng ~]#192.168.146.133/24

2.准备编译安装的基础环境

[root@chujiapeng ~]#yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed

3.准备软件包,编译并安装

[root@chujiapeng data]# tar xf nginx-1.12.2.tar.gz
[root@chujiapeng data]# cd nginx-1.12.2/

[root@chujiapeng nginx-1.12.2]# ./configure --prefix=/apps/nginx > --user=nginx > --group=nginx > --with-http_ssl_module > --with-http_v2_module > --with-http_realip_module > --with-http_stub_status_module > --with-http_gzip_static_module > --with-pcre > --with-stream > --with-stream_ssl_module > --with-stream_realip_module

[root@chujiapeng nginx-1.12.2]# make && make install
[root@chujiapeng nginx-1.12.2]# useradd nginx -s /sbin/nologin -u 2000
[root@chujiapeng nginx-1.12.2]# ll /apps/nginx/
total 0
drwxr-xr-x 2 root root 333 Sep  2 21:50 conf
drwxr-xr-x 2 root root  40 Sep  2 21:50 html
drwxr-xr-x 2 root root   6 Sep  2 21:50 logs
drwxr-xr-x 2 root root  19 Sep  2 21:50 sbin
[root@chujiapeng nginx-1.12.2]# chown nginx.nginx -R /apps/nginx/

 4.验证版本及编译参数

[root@chujiapeng nginx-1.12.2]# /apps/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

  5.启动服务并验证web页面

[root@chujiapeng sbin]# ./nginx

  linux 之 Nginx 编译安装以及配置https虚拟主机

 

 6.创建nginx 自启动脚本

[root@chujiapeng sbin]# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /apps/nginx/logs/nginx.pid
ExecStartPre=/apps/nginx/sbin/nginx -t
ExecStart=/apps/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
#KillSignal=SIGQUIT
#TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target

7.启动服务

[root@chujiapeng sbin]# systemctl start nginx
[root@chujiapeng sbin]#

linux 之 Nginx 编译安装以及配置https虚拟主机

 

 

 


2、配置虚拟主机,实现https访问www.x.com(x.com为自己定义的域名)

 

linux 之 Nginx 编译安装以及配置https虚拟主机

上一篇:在WPF中使用EFCore Migration


下一篇:win2003显示启用了inter Explorer增强的安全设置