web服务器nginx
web服务器nginx
静态,php
一、使用源码包安装nginx软件包
[root@proxy ~]# yum -y install gcc pcre-devel openssl-devel ==>>安装软件依赖包
[root@proxy ~]# useradd -s /sbin/nologin nginx ==>>创建一个用户,不可登录
[root@proxy ~]# tar -xf nginx-1.11.2.tar.gz
[root@proxy ~]# cd nginx-1.11.2/
[root@proxy nginx-1.11.2]# ./configure \
> --prefix=/usr/local/nginx \ ==>>指定安装目录
> --user=nginx \ ==>>指定用户
> --group=nginx \ ==>>指定用户组
> --with-http_ssl_module ==>>开启ssl加密认证
[root@proxy nginx-1.11.2]# make && make install
[root@proxy nginx-1.11.2]# ls /usr/local/nginx/
conf html logs sbin
[root@proxy nginx-1.11.2]# /usr/local/nginx/sbin/nginx ==>>启动nginx服务
[root@proxy nginx-1.11.2]# /usr/local/nginx/sbin/nginx -s reload ==>>不关闭服务的情况下重启nginx服务
[root@proxy nginx-1.11.2]# /usr/local/nginx/sbin/nginx -s stop ==>>停止nginx服务
[root@proxy nginx-1.11.2]# /usr/local/nginx/sbin/nginx -V ==>>查看软件信息
[root@proxy nginx-1.11.2]# netstat -antup |grep :80
-------------------------------------------------------------------------------------------------------------------------------------------------
nginx加入ststem
[root@web3 ~]# vim /usr/lib/systemd/system/nginx.service
[Unit] ==>>对服务的说明
Description=nginx - high performance web server ==>>描述服务
After=network.target remote-fs.target nss-lookup.target ==>>描述服务类别
[Service] ==>>服务的一些具体运行参数的设置
Type=forking ==>>后台运行的形式
PIDFile=/usr/local/nginx/logs/nginx.pid ==>>PID文件的路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ==>>启动准备
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ==>>启动命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload ==>>重启命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop ==>>停止命令
ExecQuit=/usr/local/nginx/sbin/nginx -s quit ==>>快速停止
PrivateTmp=true ==>>给服务分配临时空间
[Install]
WantedBy=multi-user.target
-------------------------------------------------------------------------------------------------------------------------------------------------
二、用户认证
[root@proxy ~]# cd /usr/local/nginx/conf/
[root@proxy conf]# vim nginx.conf
server {
listen 80;
server_name localhost;
auth_basic "input pass"; ==>>认证提示信息
auth_basic_user_file "/user/local/nginx/pass"; ==>>认证的密码文件
location / {
root html;
index index.html index.htm;
}
}
[root@proxy conf]# yum -y install httpd-tools
[root@proxy conf]# htpasswd -c /usr/local/nginx/pass tom ==>>创建认证用户,追加用户不使用-c选项
New password: ==>>输入密码
Re-type new password:
Adding password for user tom
[root@proxy conf]# cat /usr/local/nginx/pass
tom:$apr1$0aYyFx3K$Hg3tIyGF8thT8/64LDIOF.
[root@proxy conf]# /usr/local/nginx/sbin/nginx -s reload
三、基于域名的虚拟主机
[root@proxy conf]# vim nginx.conf ==>>修改文件,添加虚拟主机
server{
listen 80; ==>>端口
server_name www.a.com; ==>>域名
location / {
root www; ==>>网站根目录
index index.html index.htm;
}
}
server {
listen 80;
server_name www.b.com;
auth_basic "input pass";
auth_basic_user_file "/user/local/nginx/pass";
location / {
root html;
index index.html index.htm;
}
}
[root@proxy conf]# mkdir /usr/local/nginx/www ==>>为新域名添加内容
[root@proxy conf]# echo www >/usr/local/nginx/www/index.html
[root@proxy conf]# /usr/local/nginx/sbin/nginx -s reload
----------------------------------------------------------------------------------------------------
扩展:
基于端口的虚拟主机
server {
listen 80;
server_name www.b.com;
location / {
root www;
index index.html index.htm;
}
}
server {
listen 8080;
server_name www.b.com;
location / {
root html;
index index.html index.htm;
}
}
基于IP的虚拟主机
server {
listen 192.168.4.2:80;
server_name www.a.com;
location / {
root www;
index index.html index.htm;
}
}
server {
listen 192.168.4.1:80;
server_name www.b.com;
location / {
root html;
index index.html index.htm;
}
}
-----------------------------------------------------------------------------------------------------
四、SSL虚拟主机
[root@proxy nginx]# cd /usr/local/nginx/conf/
[root@proxy conf]# openssl genrsa > cert.key ==>>生成私钥
[root@proxy conf]# openssl req -new -x509 -key cert.key > cert.pem ==>>生成证书
[root@proxy conf]# vim nginx.conf
server {
listen 443 ssl; ==>>加密端口
server_name www.c.com;
ssl_certificate cert.pem; ==>>证书
ssl_certificate_key cert.key; ==>>私钥
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
[root@proxy conf]# /usr/local/nginx/sbin/nginx -s reload
- Nginx实战基础篇一 源码包编译安装部署web服务器
- 高性能Web服务器Nginx的配置与部署研究(16)小议location匹配模式优先级
- 阿里云服务器cent0S安装web环境PHP+MySql+Nginx,给nginx添加网站
- 三大WEB服务器对比分析(apache ,lighttpd,nginx)
- [转]三大WEB服务器(Apache ,Lighttpd,Nginx)对比分析
- 伪装nginx版本防止入侵web服务器
- NGINX和Squid配合搭建的Web服务器前端系统
- Web服务器#Nginx搭建
- 轻松使用Nginx搭建web服务器
- Nginx做web服务器linux内核参数优化
- 高性能Web服务器Nginx的配置与部署研究
- Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器
- 二.Nginx的web服务器搭建
- 三大WEB服务器对比分析(apache ,lighttpd,nginx)
- apache和nginx web服务器优缺点对比
- 三大WEB服务器对比分析(apache ,lighttpd,nginx)
- CentOS-6.3系统中安装配置Web服务器Nginx
- 企业Web服务器之Nginx
- NGINX Web Server Nginx web 服务器
- Nginx:轻量级高性能的Web服务器