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

12.6 Nginx安装

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

[root@martin001 conf]# chkconfig --add nginx
[root@martin001 conf]# chkconfig nginx on
[root@martin001 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
[root@martin001 conf]# /etc/init.d/nginx start
-bash: /etc/init.d/nginx: 权限不够
[root@martin001 conf]# chmod 755 /etc/init.d/nginx
[root@martin001 conf]# /etc/init.d/nginx start
Reloading systemd: [ 确定 ]
Starting nginx (via systemctl): [ 确定 ]
[root@martin001 conf]# netstat -lntp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 3729/nginx: master
[root@martin001 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
[root@martin001 html]# curl localhost/1.php
this is nginx page test.[root@martin001 html]#

12.7 默认虚拟主机

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

[root@martin001 vhost]# mkdir /data/wwwroot/default
[root@martin001 vhost]# ls !$
ls /data/wwwroot/default
[root@martin001 vhost]# vim /data/wwwroot/default/index.html
[root@martin001 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
[root@martin001 vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@martin001 vhost]# !curl
curl -x127.0.0.1:80 aaa.com
This is the default site.

12.8 Nginx用户认证

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

[root@martin001 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
[root@martin001 vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@martin001 vhost]# mkdir /data/wwwroot/test.com
[root@martin001 vhost]# echo "test.com" > /data/wwwroot/test.com/index.html
[root@martin001 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"
[root@martin001 vhost]# curl -umartin:123456 -x127.0.0.1:80 test.com
test.com

12.9 Nginx域名重定向

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

[root@martin001 vhost]# vim test.com.conf
[root@martin001 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;
}

}

[root@martin001 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
[root@martin001 vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@martin001 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

转载于:https://blog.51cto.com/12058686/2086293

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值