nginx
来源:互联网 发布:二维数组初始化为空 编辑:程序博客网 时间:2024/05/30 02:53
tar zxf nginx-1.12.0.tar.gz ##解压
useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin -u 800 nginx ##建立nginx用户
id nginx
vim nginx.h
#define NGINX_VERSION "1.0.2”
#define NGINX_VER "nginx"(修改此行,去掉后面的 “NGINX_VERSION”,为了安全,这样编译后外界无法获取程序的版本号)
vim gcc
#CFLAGS=”$CFLAGS -g” (注释掉这行,去掉debug模式编译,编译以后程序只有几百k)
./configure --prefix=/usr/local/lnmp/nginx --user=nginx --group=nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_stub_status_module
yum install pcre-devel
make && make install ##重新编译时需要清除旧的对象文件和缓存信息make clean
du -sh ##查看目录大小
curl -I localhost
2.nginx的虚拟主机
lscpu #查看cpu信息
nginx #运行 nginx
nginx -s reload #重载主配置文件
nginx -s stop #关闭 nginx
启用两个CPU:
vim /usr/local/lnmp/nginx/conf/nginx.conf
worker_processes 2; ##启用pu内核数量
worker_cpu_affinity 01 10; ##01表示启用第一个cpu内核,10表示启用第二个cpu内核
events {
worker_connections 65535; ##可以打开的最大文件数量
}
listen 80;
server_name www.westos.org;
location / {
root /web1;
index index.html;
}
}
nginx -s reload
mkdir /web1
vim /web/index.html ##建立测试页
<h1>www.westos.org</h1>
测试:浏览器访问www.westos.org
3.自签名证书
vim /usr/local/lnmp/nginx/conf/nginx.conf
server {
listen 443 ssl;
server_name localhost;
ssl_certificate cert.pem;
ssl_certificate_key cert.pem;
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.html;
}
}
}
cd /etc/pki/tls/certs
make cert.pem
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:shaanxi
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:westos
Organizational Unit Name (eg, section) []:linux
Common Name (eg, your name or your server's hostname) []:server1
Email Address []:84722207@qq.com
mv cert.pem /usr/local/lnmp/nginx/conf/
nginx -t
nginx -s reload
netstat -antlp ##查看端口有443
测试:
去浏览器访问https:172.25.4.1
查看nginx连接状态
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
#deny all; ##拒绝所有连接
}
测试:
在浏览器上访问17.25.4.1/status
在交互页面 curl localhost/status
网络重写
server {
listen 80;
server_name www.westos.org;
rewrite ^(.*)$ https://www.westos.org permanent; ##永久重定向
#rewrite ^(.*)$ https://www.westos.org redirect; ##暂时重定向
}
测试:浏览器访问www.westos.org
server1 上建立admin目录下测试页
listen 80;
server_name www.westos.org;
rewrite ^(.*)$ https://www.westos.org$1 permanent;
}
测试:浏览器访问www.westos,org/admin
反向代理结合负载均衡(轮询)
server1
vim /etc/httpd/conf/httpd.conf修改监听端口为8000
server2 为80
server3 为8080
vim /usr/local/lnmp/nginx/conf/nginx.conf
http {
upstream westos {
server 172.25.4.2:80;
server 172.25.4.3:8080;
server 127.0.0.1:8000 backup; ##如果两个都停了,就返回
}
server {
listen 80;
server_name www.westos.org;
# rewrite ^(.*)$ https://www.westos.org$1 permanent;
location / {
proxy_pass http://westos;
}
vim /var/www/html/index.html
当前页面正在维护。。。。。。
server2<h1>server2-www.westos.org</h1>
server3
<h1>server3-www.westos.org</h1>
测试:
浏览器访问www.westos.org
先是只开启server1的http
然后是都开启server2和server3的http实现了轮询
IP哈希
http {
upstream westos {
ip_hash; ##ip哈希,除非该ip挂掉,不然以后一直访问该IP
server 172.25.4.2:80;
server 172.25.4.3:8080;
#server 127.0.0.1:8000 backup;
}
浏览器访问www.westos.org一直都是一个页面
- nginx
- Nginx
- Nginx
- Nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- 漫画告诉你什么是DDoS攻击?
- POJ 1905
- github第三弹:管理自己的学习计划
- CCNA第三天实验
- CentOS7之Firewall防火墙配置用法详解(推荐)<我见到的最全说明>
- nginx
- jsp实现Excel文件导入到MySQL数据库中
- 解析动态代理
- pyspark中combineByKey的两种理解方法
- UVA 10006
- 欢迎使用CSDN-markdown编辑器
- Android通知栏点击事件
- 无缝滚动
- JUC锁-07之 LockSupport