运维第七天笔记

上传
scp -r 源路径 用户名@IP地址:目标路径
scp -r nginx-1.10.3.tar.gz [email protected]:/opt/
下载
scp -r 用户名@IP地址:源路径 目标路径
scp -r [email protected]:/opt/wf.txt /root/
常见的web服务器:
unix和Linux:apache nginx tengine tomcat
nginx:
俄罗斯人编写的轻量级轻量级http服务器
是一个高性能的http和反向代理服务器,
同时也是一个IMAP、pop3/smtp代理服务器
Linux安装软件有哪几种方式:
yum
编译安装 - --》gcc

yum -y install gcc pcre-devel openssl-devel
useradd nginx 
[root@host1 nginx-1.10.3]# ./configure \
>  --prefix=/usr/local/nginx \	#指定安装目录
>  --user=nginx \				#指定账户名称
> --group=nginx \				#指定名称组
> --with-http_ssl_module		#支持加密功能
make   && make install  
nginx 配置文件简介
http  80
nginx  端口号:80
/usr/local/nginx/ #安装目录
conf/nginx.conf 	#主配置文件
html	#网页目录
logs    #日志文件
sbin/nginx	#启动脚本	
/usr/local/nginx/sbin -v 查看NGINX版本信息
/usr/local/nginx/sbin    启动服务
/usr/local/nginx/sbin -s  reload 重新加载配置文件 
/usr/local/nginx/sbin -s  stop  关闭服务

##############################################
[root@host1 opt]# tar -xf nginx-1.12.2.tar.gz
nginx-1.10.3 nginx-1.12.2
nginx-1.10.3.tar.gz nginx-1.12.2.tar.gz
[root@host1 opt]# cd nginx-1.12.2/
[root@host1 nginx-1.12.2]# ./configure
–prefix=/usr/local/nginx
–user=nginx --group=nginx
–with-http_ssl_module
[root@host1 nginx-1.12.2]# make
[root@host1 nginx-1.12.2]#
mv /usr/local/nginx/sbin/nginx #改名旧脚本
/usr/local/nginx/sbin/nginxold
[root@host1 nginx-1.12.2]#
cp objs/nginx /usr/local/nginx/sbin/ #复制新脚本
[root@host1 nginx-1.12.2]# make upgrade #升级软件
[root@host1 nginx-1.12.2]#
/usr/local/nginx/sbin/nginx -v 查看版本
########################################
配置文件解析:
全局配置:
http{

server {				#定义虚拟主机
    listen       80;
    server_name  localhost;
	        location / {		发布目录
        root   html;
        index  index.html index.htm;
						}		
		}
server {				#定义虚拟主机
    listen       80;
    server_name  www.b.com;
	        location / {		发布目录
        root   www;
        index  index.html index.htm;
						}		
		}

}
[root@host1 nginx]# mkdir www
[root@host1 nginx]# cd www/
[root@host1 www]# echo www.b.com > index.html
[root@host1 www]# nginx -s reload

user nginx; #进程所有者
worker_processes 1; #启动进程数量
error_log logs/error.log; 日志文件
pid logs/nginx.pid; PID文件
events {
worker_connections 1024; 单个进程最大并量
}

########################################
添加虚拟主机 域名为:www.c.com 网页内容为:
www.c.com
加密算法一般分为:对称加密 非对称加密 信息摘要
对称算法:aes EDS 主要应用于单机数据加密
非对称算法:RSA DSA 主要用于网络数据加密
信息摘要:md5 sha256 主要应用于数据完整性校验
[root@host1 conf]# pwd
/usr/local/nginx/conf
[root@host1 conf]#
openssl genrsa > cert.key #生成私钥
[root@host1 conf]#
openssl req -new -x509 -key cert.key > cert.pem
[root@host1 conf]# vim nginx.conf

server {
        listen       443 ssl;
        server_name  www.a.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;
}
}

########################################
主流网站平台:
lnmp
lamp
什么是了lnmp
L:linux操作系统
N:Nginx网站服务软件
M:Mysql mariadb
P:网站开发语言:(php perl python)
部署lnmp:
[root@host1 ~]# yum -y install mariadb mariadb-server mariadb-devel
[root@host1 ~]# yum -y install php php-mysql
[root@host1 ~]# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm --nodeps
警告:php-fpm-5.4.16-42.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中… ################################# [100%]
软件包 php-fpm-5.4.16-42.el7.x86_64 已经安装
[root@host1 ~]# systemctl restart php-fpm
[root@host1 ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@host1 ~]# systemctl restart mariadb
[root@host1 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/syst
vim /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000 监听端口
pm.max_children = 32 #最大进程数量
pm.start_servers = 15 #最小进程数量
pm.min_spare_servers = 5 #最小需要几个空闲进程
pm.max_spare_servers = 32 #
最多允许几个进程处于空闲状态
vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
[root@host1 html]#
cat /usr/local/nginx/html/index.php

<?php $i="123456"; echo $i; ?>

##########################################
地址重写:
什么是地址重写:
获得一个来访的URL请求,然后改成服务器可以处理的
另一个请求
地址重写的好处:
缩短URL,隐藏实际路径提供安全性
易于用户记忆和键入
易于被搜索引擎收录
开源中国
rewrite 基本语句
rewrite /a.html /b.html redirect;
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.a.com;
rewrite /a.html /b.html redirect;
}

########################
这个是80端口被占用,关闭80端口对应的服务。重启nginx就OK
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
####################################

本章需要设置IP地址
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/lichong2259/article/details/89222646
今日推荐