美文网首页
新架构第3天

新架构第3天

作者: Liang_JC | 来源:发表于2020-08-05 14:11 被阅读0次

Q1、基于location实现基于域名虚拟主机

[root@Centos7 ~]# cd /apps/nginx/conf.d/
[root@Centos7 conf.d]# vim web.conf
server_tokens off;

server {
        listen 192.168.37.87:80;
        server_name test.magedu.net;
        location / {
                root /data/site1;
                index index.html;
        }
}
[root@Centos7 conf.d]# echo test > /data/site1/index.html
[root@Centos7 conf.d]# nginx 

#客户端测试
[root@centos6 ~]$ curl test.magedu.net
test

测试结果:

image.png

Q2、nginx自定义日志路径,配置访问日志为json格式

[root@Centos7 conf.d]# vim ../conf/nginx.conf
http {
        log_format json '{"@timestamp":"$time_iso8601",'
        '"host":"$server_addr",'
        '"clientip":"$remote_addr",'
        '"size":$body_bytes_sent,'
        '"responsetime":$request_time,'
        '"upstreamtime":"$upstream_response_time",'
        '"upstreamhost":"$upstream_addr",'
        '"http_host":"$host",'
        '"uri":"$uri",'
        '"domain":"$host",'
        '"xff":"$http_x_forwarded_for",'
        '"referer":"$http_referer",'
        '"tcp_xff":"$proxy_protocol_addr",'
        '"http_user_agent":"$http_user_agent",'
        '"status":"$status"}';
}
[root@Centos7 conf.d]# vim web.conf
server_tokens off;

server {
        listen 192.168.37.87:80;
        server_name test.magedu.net;
        access_log logs/test.magedu.net.access.log json;
        location / {
                root /data/site1;
                index index.html;
        }
}
[root@Centos7 conf.d]# nginx -s reload

#修改后的日志
[root@Centos7 conf.d]# tail /apps/nginx/logs/test.magedu.net.access.log 
192.168.37.1 - - [29/Jul/2020:20:43:47 +0800] "GET / HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
192.168.37.1 - - [29/Jul/2020:20:43:47 +0800] "GET /favicon.ico HTTP/1.1" 404 548 "http://test.magedu.net/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
192.168.37.6 - - [29/Jul/2020:20:46:05 +0800] "GET / HTTP/1.1" 200 5 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
{"@timestamp":"2020-07-29T20:53:06+08:00","host":"192.168.37.87","clientip":"192.168.37.6","size":5,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"test.magedu.net","uri":"/index.html","domain":"test.magedu.net","xff":"-","referer":"-","tcp_xff":"","http_user_agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2","status":"200"}
{"@timestamp":"2020-07-29T20:53:07+08:00","host":"192.168.37.87","clientip":"192.168.37.6","size":5,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"test.magedu.net","uri":"/index.html","domain":"test.magedu.net","xff":"-","referer":"-","tcp_xff":"","http_user_agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2","status":"200"}

Q3、nginx实现https证书

1、生成CA证书
[root@Centos7 conf.d]# cd /etc/pki/tls/certs/
[root@Centos7 certs]# vim Makefile
 57         #/usr/bin/openssl genrsa -aes128 $(KEYLEN) > $@
 58         /usr/bin/openssl genrsa $(KEYLEN) > $@
[root@Centos7 certs]# make magedu.net.crt
umask 77 ; \
#/usr/bin/openssl genrsa -aes128 2048 > magedu.net.key
/usr/bin/openssl genrsa 2048 > magedu.net.key
Generating RSA private key, 2048 bit long modulus
.......................................................+++
..........................................+++
e is 65537 (0x10001)
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key magedu.net.key -x509 -days 365 -out magedu.net.crt 
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:GuangDong
Locality Name (eg, city) [Default City]:GuangZhou
Organization Name (eg, company) [Default Company Ltd]:magedu.net
Organizational Unit Name (eg, section) []:opt
Common Name (eg, your name or your server's hostname) []:test.magedu.net
Email Address []:

[root@Centos7 certs]# mkdir /apps/nginx/ssl/
[root@Centos7 certs]# mv magedu.net.* /apps/nginx/ssl/
[root@Centos7 certs]# vim /apps/nginx/conf.d/web.conf
server_tokens off;

server {
        listen 192.168.37.87:80;
        listen 192.168.37.87:443 ssl;
        server_name test.magedu.net;
        access_log logs/test.magedu.net.access.log json;
        ssl_certificate /apps/nginx/ssl/magedu.net.crt;
        ssl_certificate_key /apps/nginx/ssl/magedu.net.key;
        ssl_session_cache shared:sslcache:20m;
        ssl_session_timeout 10m;
        location / {
                root /data/site1;
                index index.html;
                if ( $scheme = http ) {
                        rewrite ^/(.*)$ https://test.magedu.net/$1 permanent;
                }
        }
}
[root@Centos7 certs]# nginx -s reload

#客户端测试
[root@centos6 ~]$ curl test.magedu.net
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
[root@centos6 ~]$ curl -kL test.magedu.net
test
image.png

相关文章

  • 海量运维、运营规划之道

    第1部分质量 第1章规划/2 1.1架构规划/2 1.1.1新趋势、新机遇、新挑战/2 1.1.2产品、架构、成本...

  • 新架构第1天

    Q1、Ubuntu server18.04的安装,优化系统 选择安装语言image.png 选择第一项安装serv...

  • 新架构第2天

    Q1、几种IO模型的原理 阻塞IO模型应用程序接收到用户一个请求,应用程序发起系统调用内核完成工作,内核从网络或者...

  • 新架构第3天

    Q1、基于location实现基于域名虚拟主机 测试结果: Q2、nginx自定义日志路径,配置访问日志为json...

  • 新架构第5天

    Q1、rewrite几种规则案例演示区别 Q2、使用proxy反向代理后端多台web服务器

  • 新架构第6天

    Q1、编译安装tengine,openresty Q2、搭建基于LNMP的WordPress站点 Q3、详解hap...

  • MVC和MVP

    Android mvp 架构的自述 如何更高效的使用MVP以及官方MVP架构解析 老的MVC架构 新的MVP架构 ...

  • 2019-08-26

    架构设计 新的一周,新的迭代~新的迭代要做消息中心,今天下午一直在写架构设计文档。这次架构设计文档,我以专栏 - ...

  • 新一代银行 IT 架构

    第 1 章 引言 第 2 章 分布式架构理论及典型实践 第 3 章 当前主流的 IT 架构分析 第 4 章 新一代...

  • 数据库ROOM-Google新推

    前言 今年,谷歌新推了不少东西,在看其新架构Architecture Components(AC架构是一个类似M...

网友评论

      本文标题:新架构第3天

      本文链接:https://www.haomeiwen.com/subject/xcdicktx.html