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

 

posted @ 2019-03-29 20:05  Eric.TSE  阅读(227)  评论(0编辑  收藏  举报