服务端 | ip | 环境 |
---|---|---|
server1 | 172.25.55.1 | 关闭防火墙,添加域名解析 |
founcation55 | 172.25.55.250 | 关闭防火墙,添加域名解析 |
[root@server1 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx/
--with-http_realip_module --with-http_image_filter_module=dynamic --with-http_ssl_module
[root@server1 nginx-1.14.2]# yum install openssl-devel -y
[root@server1 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx/
--with-http_realip_module --with-http_image_filter_module=dynamic
--with-http_ssl_module
[root@server1 nginx-1.14.2]# make
[root@server1 nginx-1.14.2]# cd objs/
[root@server1 objs]# cp nginx /usr/local/nginx/sbin/
[root@server1 objs]# cp ngx_http_image_filter_module.so /usr/local/nginx/modules/(没有modules目录,手动创建)
编辑nginx的配置文件:
[root@server1 certs]# vim /usr/local/nginx/conf/nginx.conf
134 server {
135 listen 80;
136 server_name www.westos.org;
137
138 location / {
139 root /web;(访问的资源路径)
140 index index.html;
141 }
142
143 }
[root@server1 certs]# nginx -s reload(重载服务)
创建/web目录编辑网页文件index.html。
客户端添加域名解析:
[root@foundation55 新6]# cat /etc/hosts
172.25.55.1 www.westos.org bbs.westos.org
常见http状态码含义:
状态码 | 含义 |
---|---|
200 | 请求成功 |
301 | 被请求的资源已永久移动到新位置 |
302 | 请求的资源临时从不同的 URI响应请求 |
404 | 请求失败 |
添加证书
[root@server1 objs]# cd /etc/pki/tls/certs
[root@server1 certs]# make cert.pem
将证书文件复制到nginx下的conf目录下:
[root@server1 certs]# cp cert.pem /usr/local/nginx/conf/
编辑nginx配置文件:
[root@server1 certs]# vim /usr/local/nginx/conf/nginx.conf
100 server {
101 listen 443 ssl;
102 server_name www.westos.org;
103
104 ssl_certificate cert.pem;
105 ssl_certificate_key cert.pem;
106
107 ssl_session_cache shared:SSL:1m;
108 ssl_session_timeout 5m;
109
110 ssl_ciphers HIGH:!aNULL:!MD5;
111 ssl_prefer_server_ciphers on;
112
113 location / {
114 root /web;
115 index index.html index.htm;
116 }
117 }
118
119 server {
120 listen 80;
121 server_name www.westos.org;
122 rewrite ^/(.*)$ https://www/westos/org/$1;
123
124
125
126 location / {
127 root /web;
128 index index.html;
129 }
130
131 }
[root@server1 certs]# nginx -s reload
[root@server1 certs]# vim /usr/local/nginx/conf/nginx.conf
122 rewrite ^/(.*)$ https://www/westos/org/$1 permanent;
服务端server1/web目录下创建一个test.html网页文件。
[root@server1 web]# cat test.html
test
[root@server1 certs]# vim /usr/local/nginx/conf/nginx.conf
122 rewrite ^/(.*)$ https://www/westos/org/$1 permanent;
[root@server1 web]# vim /usr/local/nginx/conf/nginx.conf
124 rewrite ^/(.*)$ https://www/westos/org/ permanent;
[root@server1 bbs]# vim /usr/local/nginx/conf/nginx.conf
121 server {
122 listen 80;
123 server_name bbs.westos.org;
124
125
126
127 location / {
128 root /bbs;
129 index index.html;
130 }
131
132 }
创建/bbs目录,并编辑网页文件:
[root@server1 web]# mkdir /bbs
[root@server1 web]# cd /bbs/
[root@server1 bbs]# ls
[root@server1 bbs]# vim index.html
bbs.westos.org
[root@server1 bbs]# vim /usr/local/nginx/conf/nginx.conf
121 server {
122 listen 80;
123 server_name www.westos.org;
124 rewrite ^/bbs$ http://bbs.westos.org permanent;
125 #rewrite ^/bbs(.*)$ http://bbs.westos.org/$1 permanent;
126 location / {
127 root /web;
128 index index.html;
129 }
130
131 }
132
133 server {
134 listen 80;
135 server_name bbs.westos.org;
136
137 location / {
138 root /bbs;
139 index index.html;
140 }
141 }
在浏览器访问http://www.westos.org/bbs,结果如下图。
[root@server1 bbs]# vim /usr/local/nginx/conf/nginx.conf
124 rewrite ^/bbs$ http://bbs.westos.org permanent;
125 rewrite ^/bbs(.*)$ http://bbs.westos.org/$1 permanent;
在浏览器访问http://www.westos.org/bbs/index.html,结果如下图。
[root@server1 bbs]# cd /web/
[root@server1 web]# cp -r /bbs/ /web/
[root@server1 web]# ls
bbs index.html test.html