12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx相关的知识,希望对你有一定的参考价值。

12.6 nginx安装

技术分享图片

[[email protected] conf]# chkconfig --add nginx
[[email protected] conf]# chkconfig nginx on
[[email protected] conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[[email protected] conf]# /etc/init.d/nginx start
-bash: /etc/init.d/nginx: 权限不够
[[email protected] conf]# chmod 755 /etc/init.d/nginx
[[email protected] conf]# /etc/init.d/nginx start
Reloading systemd: [ 确定 ]
Starting nginx (via systemctl): [ 确定 ]
[[email protected] conf]# netstat -lntp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 3729/nginx: master
[[email protected] conf]# ps -aux |grep nginx
root 3729 0.0 0.0 20496 628 ? Ss 23:23 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 3730 0.0 0.3 22940 3200 ? S 23:23 0:00 nginx: worker process
nobody 3731 0.0 0.3 22940 3200 ? S 23:23 0:00 nginx: worker process
root 3736 0.0 0.0 112676 956 pts/0 R+ 23:29 0:00 grep --color=auto nginx
[[email protected] html]# curl localhost/1.php
this is nginx page test.[[email protected] html]#

12.7 默认虚拟主机

技术分享图片

[[email protected] vhost]# mkdir /data/wwwroot/default
[[email protected] vhost]# ls !$
ls /data/wwwroot/default
[[email protected] vhost]# vim /data/wwwroot/default/index.html
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload
[[email protected] vhost]# !curl
curl -x127.0.0.1:80 aaa.com
This is the default site.

12.8 Nginx用户认证

技术分享图片

[[email protected] vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload
[[email protected] vhost]# mkdir /data/wwwroot/test.com
[[email protected] vhost]# echo "test.com" > /data/wwwroot/test.com/index.html
[[email protected] vhost]# curl -I -x127.0.0.1:80 test.com
HTTP/1.1 401 Unauthorized
Server: nginx/1.12.1
Date: Tue, 13 Mar 2018 16:21:36 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive
WWW-Authenticate: Basic realm="Auth"
[[email protected] vhost]# curl -umartin:123456 -x127.0.0.1:80 test.com
test.com

12.9 Nginx域名重定向

技术分享图片

[[email protected] vhost]# vim test.com.conf
[[email protected] vhost]# cat test.com.conf
server
{
listen 80;
server_name test.com test1.com test2.com;
index index.html index.htm index.php;
root /data/wwwroot/test.com;
if ($host != ‘test.com‘ ) {
rewrite ^/(.*)$ http://test.com/$1 permanent;
}

}

[[email protected] vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload
[[email protected] vhost]# curl -x127.0.0.1:80 test1.com/123.txt -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.1
Date: Tue, 13 Mar 2018 16:37:07 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/123.txt

以上是关于12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx的主要内容,如果未能解决你的问题,请参考以下文章

12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx

12.6 Nginx安装12.7 默认虚拟主机12.8Nginx用户认证12.9Nginx域名重定向

12.6 Nginx安装;12.7 Nginx默认虚拟主机;12.8 Nginx用户认证;12.9

12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx域名重定向

2018-6-7

2018.3.13 12周2次课