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

原文地址:http://blog.51cto.com/12058686/2086293

时间: 2024-10-09 22:20:16

12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx的相关文章

12.Nginx介绍,安装,配置默认虚拟主机,重定向

[toc] 12.5 Nginx介绍 官网:nginx.org 因为nginx处理静态文件的能力要比apache好很多,所以很多企业在建站的时候一般都是用java写的,然后会选择tomcat,但是tomcat处理静态文件的能力不是太好就会叠加选择nginx. nginx特点: 体积小 处理能力强 并发高 可扩展性好 Nginx应用场景: web服务 反向代理 负载均衡 Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大

Nginx安装与配置:默认虚拟主机、用户认证和域名重定向

一.Nginx安装 1.下载并解压安装包 [[email protected] ~]# cd /usr/local/src/ [[email protected] src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz [[email protected] src]# tar zxf nginx-1.12.2.tar.gz 2.配置编译选项 [[email protected] src]# cd nginx-1.12.2 [[email 

90.Nginx安装与配置:默认虚拟主机、用户认证和域名重定向

一.Nginx安装 1.下载并解压安装包 [[email protected] ~]# cd /usr/local/src/[[email protected] src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz[[email protected] src]# tar zxf nginx-1.12.2.tar.gz 2.配置编译选项 [[email protected] src]# cd nginx-1.12.2[[email pro

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

扩展: nginx.conf 配置详解 : http://www.ha97.com/5194.html http://my.oschina.net/duxuefeng/blog/34880 nginx rewrite四种flag : http://www.netingcn.com/nginx-rewrite-flag.html http://unixman.blog.51cto.com/10163040/1711943 12.6 Nginx安装 1. 进入下载安装包目录: [[email pro

2018-3-13 12周2次课 Nginx安装、默认虚拟主机、用户认证、域名重定向

12.6 Nginx安装 [[email protected] ~]# cd /usr/local/src/ [[email protected] src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz (过程省略) [[email protected] src]# tar zxvf nginx-1.12.2.tar.gz [[email protected] src]# cd nginx-1.12.2/ [[email protecte

十二周二次课 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.

十二周二次课 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx域名重定向 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx域名重定向 原文地址:http://blog.51cto.com/wbyyy/2087031

Nginx安装,默认虚拟主机以及认证和重定向

Nginx安装 1.首先下载安装包 [[email protected] src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz --2018-03-14 00:46:57-- http://nginx.org/download/nginx-1.12.2.tar.gz 正在解析主机 nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...

Nginx安装、默认虚拟主机、用户认证、nginx中PHP解析

12.6 Nginx安装 准备工作 安装包 [[email protected] ~]# cd /usr/local/src/ 下载安装包:[[email protected] src]# wget http://nginx.org/download/nginx-1.12.1.tar.gz 解压:[[email protected] src]# tar zxvf nginx-1.12.1.tar.gz 安装 环境配置 [[email protected] src]# cd nginx-1.12.

十二周二课 Nginx安装、Nginx默认虚拟主机、Nginx用户认证、Nginx域名重定向

Nginx安装 首先进入/usr/local/src目录.然后下载Nginx.wget http://nginx.org/download/nginx-1.12.1.tar.gz然后解压tar zxf nginx-1.12.1.tar.gz然后进入我们刚才解压好的目录进行编译cd nginx-1.12.1[[email protected] nginx-1.12.1]# ./configure --prefix=/usr/local/nginx这里没有加编译参数,我们可以根据实际情况,在后期编译