zoukankan      html  css  js  c++  java
  • 04.nginx使用

    博客为日常工作学习积累总结:

    1.安装依赖包

          安装pcre :yum install pcre pcre-devel -y

               安装openssl:yum install openssl openssl-devel -y

               检查安装包:rpm -qa pcre pcre-devel

                       pcre-7.8-7.el6.x86_64

                       pcre-devel-7.8-7.el6.x86_64

               切换至国内yum源:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

               安装nginx:地址:http://nginx.org/download/nginx-1.14.2.tar.gz

          创建安装用户:useradd oldboy    passwd oldboy 

               放置路径:/home/oldboy/tools

                   网络下载:wget -q http://nginx.org/download/nginx-1.14.2.tar.gz

                   解压:tar xf nginx-1.14.2.tar.gz

                        ls           auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

                       查看nginx安装包:yum list | grep nginx

                  为配置文件添加用户:useradd nginx 

                  配置文件:./configure --prefix=/application/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_mp4_module --with-http_flv_module     

               ./configure --help

             编译:make (make & make install)

             编译后安装:make install

                  将带版本的去掉创建软连接:ln -s /application/nginx-1.6.3/ /application/nginx

                  启动:/application/nginx/sbin/nginx

                       查询端口:netstat -lntup|grep 80       lsof -i :80

                       查看nginx版本:/application/nginx/sbin/nginx -V

                  优化去掉注释:egrep -v "#|^$" nginx.conf.default >nginx.conf

                   /application/nginx/sbin/nginx -t

                   /application/nginx/sbin/nginx -s reload

            ln -n /application/nginx/sbin/nginx  /usr/bin/nginx

    2.设置开机自启动:

          参考链接:https://www.cnblogs.com/jepson6669/p/9131217.html

          进入到:cd /lib/systemd/system/

          创建服务文件:vim nginx.service

     1 [Unit]
     2 Description=nginx service
     3 After=network.target 
     4    
     5 [Service] 
     6 Type=forking 
     7 ExecStart=/application/nginx/sbin/nginx
     8 ExecReload=/application/nginx/sbin/nginx -s reload
     9 ExecStop=application/nginx/sbin/nginx -s quit
    10 PrivateTmp=true 
    11    
    12 [Install] 
    13 WantedBy=multi-user.target

          加入开机自启动:systemctl enable nginx

          取消开机自启动:systemctl disable nginx

          常用命令使用:          

                systemctl start nginx.service          启动nginx服务

                systemctl stop nginx.service           停止服务

                systemctl restart nginx.service        重新启动服务

                systemctl list-units --type=service     查看所有已启动的服务

                systemctl status nginx.service          查看服务当前状态

                systemctl enable nginx.service          设置开机自启动

                systemctl disable nginx.service         停止开机自启动

          常见错误处理:systemctl daemon-reload

    3.跑一个项目测试:

     1 worker_processes  1;
     2 
     3 events {
     4 
     5     worker_connections  1024;
     6 
     7 }
     8 
     9 http {
    10 
    11     include       mime.types;
    12 
    13     default_type  application/octet-stream;
    14 
    15     sendfile        on;
    16 
    17     keepalive_timeout  65;
    18 
    19     upstream ofmovie {
    20 
    21         server 192.168.50.188:5001;
    22 
    23         server 192.168.50.188:5002;
    24 
    25         server 192.168.50.188:5003;
    26 
    27         server 192.168.50.188:5004;
    28 
    29     }
    30 
    31     server {
    32 
    33         listen       80;
    34 
    35         server_name  ofmovie.flybird.com;
    36 
    37         location / {
    38 
    39             root   html;
    40 
    41             index  index.html index.htm;
    42 
    43             proxy_pass http://ofmovie;
    44 
    45         }
    46 
    47     }
    48 
    49 }

         

            运行自己做的项目:

              [root@mould ~]# cd /data/movie/

              nohup python manage.py runserver -h 192.168.50.188 -p 5001

              nohup python manage.py runserver -h 192.168.50.188 -p 5002

              nohup python manage.py runserver -h 192.168.50.188 -p 5003

              nohup python manage.py runserver -h 192.168.50.188 -p 5004

  • 相关阅读:
    CodeBlocks下载与安装教程
    Delphi 资源管理器套件
    做了一个 62 进制的简单实现
    关于 TRegEx.Split()
    Delphi 的链式代码
    在Linux上编译dotnet cli的源代码生成.NET Core SDK的安装包
    尝试解决在构造函数中同步调用Dns.GetHostAddressesAsync()引起的线程死锁
    .NET Core中遇到奇怪的线程死锁问题:内存与线程数不停地增长
    将asp.net core站点发布到IIS上遇到的问题
    .NET Core 构建配置文件从 project.json 到 .csproj
  • 原文地址:https://www.cnblogs.com/ericchengge677/p/10623629.html
Copyright © 2011-2022 走看看