• nginx


    1.0 Nginx介绍

    • Nginx官网 nginx.org,最新版1.13,最新稳定版1.12
    • Nginx应用场景:web服务、反向代理、负载均衡
    • Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大区别在于Tenging增加了一些定制化模块,在安全限速方面表现突出,另外它支持对js,css合并
    • Nginx核心+lua相关的组件和模块组成了一个支持lua的高性能web容器openresty,参考http://jinnianshilongnian.iteye.com/blog/2280928

    http1.1版本–host(域名) 一个web服务器可以有多个站点,一个站点就是一个虚拟主机。定义虚拟主机的名字用域名来定义。

    1.1 如何检测80端口通不通安装telnet

    # yum install -y telnet
    

    1.2 检测80端口

    # telnet 192.168.109.133 80
    Trying 192.168.109.133...
    telnet: connect to address 192.168.109.133: No route to host
    

    1.3 说明80端口是不通的,centos7自带firewalld服务,开启状态。建议不要关闭防火墙。做实验想简单点可以关闭

    # systemctl stop firewalld
    

    1.4 或者添加80端口

    # firewall-cmd --add-port=80/tcp --permanent
    

    1.5 添加80端口还需要重载生效

    # firewall-cmd --reload
    

    1.6 现在自定义host到Windows上去设置,因为我们没有购买此域名,配置centos.com配置文件centos.com.conf

    server
    {
        listen 80;
        server_name centos.com;
        index index.html index.htm index.php;
        root /data/wwwroot/default;
    }
    

    1.7 配置aaa.com配置文件aaa.com.conf

    server
    {
        listen 80 default_server;
        server_name aaa.com;
        index index.html index.htm index.php;
        root /data/wwwroot/aaa.com;
    }
    

    默认虚拟主机:就是nginx的第一个虚拟主机,泛解析、禁掉默认虚拟主机,加一行deny all;

     1.8 做个博客站点vim blog.linux.com.conf

    server
    {
        listen 80 default_server;
        server_name blog.linux.com;
        deny all;
    
        index index.html index.htm index.php;
        root /data/wwwroot/blog.linux.com;
    }
    

    1.9 需要创建/data/wwwroot/blog.linux.com 的目录

    # mkdir /data/wwwroot/blog.linux.com
    

    2.0 安装wrodpress,需要配置blog.linux.com配置文件解析php

    server
        {
            listen 80;
            server_name blog.linux.com www.luquan.com;
            if ( $host = blog.linux.com )
            {
               rewrite /(.*) http://www.luquan.com/$1 permanent;
            }
            index index.html index.htm index.php;
            root /data/wwwroot/blog.linux.com;
    
            location ~ .php$ 
            {
                include fastcgi_params;
                fastcgi_pass unix:/tmp/php-fcgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /data/wwwroot/blog.linux.com$fastcgi_script_name;
            }    
     }
    

    官网下载

    解压wordpress

    移动位置

    # mv wordpress/* /data/wwwroot/bolg.linux.com
    

    设置Windows的hotts-blog.linux.com添加 访问blog.linux.com安装

    2.1 设置数据库

    create database blog;
    

    2.2 创建用户

    grant all on blog.* to ‘blog’@‘127.0.0.1’ identified by ‘123456’;
    

    2.3 切换某个库

    use blog;
    

     2.4 查询库里有什么表

    show tables;
    

    2.5 问题处理:在安装wordoress过程中,需要设定网站程序目录权限,属主设定为php-fpm服务的那个用户:

    # chown -R php-fpm /data/wwwroot/blog.linux.com
    

    输入域名照着提示安装wordpress即可

    3.0 安装discuz

    # yum install -y git
    

    3.1 克隆discuz到root目录下

    # git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git
    

    3.2 拷贝upload到bbs.lingx.com

    # cp -r DiscuzX/upload  /data/wwwroot/bbs.linux.com
    

    3.3 定义虚拟主机配置文件

    # cp blog.linux.com.conf bbs.linux.com.conf
    

    3.4 修改bbs.linux.com.conf里面的目录vim命令模式下

    :1,$s/blog.linux.com/bbs.linux.com/g
    

    3.5 重载配置文件

    # /usr/local/nginx/sbin/nginx -t
    # /usr/local/nginx/sbin/nginx -s reload
    

    3.6 开始安装,进入跟目录给权限

    # cd /data/wwwroot/bbs.linux.com
    # chown -R php-fpm config data us_server/data uc_client/data
    

    3.7 定义数据库相关操作进入数据库,创建库

    # create database bbs
    

    3.8 创建用户

    # grant all on bbs.* to 'bbs'@127.0.0.1 identified by '123456';
    

    安装discuz

    4.0 域名重定向

    两个域名从一个域名跳转到另外一个域名

    配置blog.linux.com.conf,假如说你还有一个域名www.linux.com两个都不想舍弃

    server
        {
            listen 80;
            server_name blog.linux.com www.linux.com;
            if ( $host = blog.linux.com )
            {
               rewrite /(.*) http://www.linux.com/$1 permanent;
            }
            index index.html index.htm index.php;
            root /data/wwwroot/blog.linux.com;
    
            location ~ .php$
            {
                include fastcgi_params;
                fastcgi_pass unix:/tmp/php-fcgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /data/wwwroot/blog.linux.com$fastcgi_script_name;
            }
     }
    

    添加这一行

    if ( $host = blog.linux.com )
            {
               rewrite /(.*) http://www.linux.com/$1 permanent;
            }
    

    解释访问blog.linux.com/?p=1就会跳转到www.linux.com/?p=1

    premanent是状态码

    检测语法重载

    # /usr/local/nginx/sbin/nginx -t
    # /usr/local/nginx/sbin/nginx -s reload
    

    测试

    # curl -x127.0.0.1:80 -I blog.linux.com/?p=1
    HTTP/1.1 301 Moved Permanently
    Server: nginx/1.17.0
    Date: Sat, 12 Oct 2019 12:21:05 GMT
    Content-Type: text/html
    Content-Length: 169
    Connection: keep-alive
    Location: http://www.linux.com/?p=1 ##着重看着这行
    

    测试不存在的页面

    # curl -x127.0.0.1:80 -I blog.linux.com/abc/admin/1.txt
    HTTP/1.1 301 Moved Permanently
    Server: nginx/1.17.0
    Date: Sat, 12 Oct 2019 12:23:07 GMT
    Content-Type: text/html
    Content-Length: 169
    Connection: keep-alive
    Location: http://www.linux.com/abc/admin/1.txt
    

    状态码:200(ok) 404(不存在)304(缓存)301(永久重定向)302(临时重定向)

    知识:如果是域名跳转用301,如果不涉及域名跳转用302

    测试,修改配置文件

    server
        {
            listen 80;
            server_name blog.linux.com www.linux.com;
            if ( $host = blog.linux.com )
            {
               rewrite /(.*) http://www.linux.com/$1 permanent;
            }
               rewrite /1.txt /2.txt redirect;
            index index.html index.htm index.php;
            root /data/wwwroot/blog.linux.com;
    
            location ~ .php$
            {
                include fastcgi_params;
                fastcgi_pass unix:/tmp/php-fcgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /data/wwwroot/blog.linux.com$fastcgi_script_name;
            }
     }
    

    重载配置文件

    用www.linux.com测试因为blog.linux.com已经做了跳转

    # curl -x127.0.0.1:80 -I www.linux.com/1.txt
    HTTP/1.1 302 Moved Temporarily
    Server: nginx/1.17.0
    Date: Sat, 12 Oct 2019 12:24:36 GMT
    Content-Type: text/html
    Content-Length: 145
    Location: http://www.linux.com/2.txt
    Connection: keep-alive
    

    着重看状态码

  • 相关阅读:
    进程池,线程池,协程,gevent模块,协程实现单线程服务端与多线程客户端通信,IO模型
    线程相关 GIL queue event 死锁与递归锁 信号量l
    生产者消费者模型 线程相关
    进程的开启方式 进程的join方法 进程间的内存隔离 其他相关方法 守护进程 互斥锁
    udp协议 及相关 利用tcp上传文件 socketserver服务
    socket套接字 tcp协议下的粘包处理
    常用模块的完善 random shutil shevle 三流 logging
    day 29 元类
    Django入门
    MySQL多表查询
  • 原文地址:https://www.cnblogs.com/yantou/p/11663693.html
Copyright © 2020-2023  润新知