服务器自带的python版本为2.7,需要升级到python3
x# yum -y groupinstall "Development tools"yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-develyum -y install libffi-devel
这里面 libffi-devel 包很关键,因为只有3.7才会用到这个包。
xxxxxxxxxx#yum安装wgetyum -y install wget# 下载wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz#解压源码包tar -zxvf Python-3.7.0.tgz#创建安装目录mkdir /usr/local/python3cd Python-3.7.0/#安装到指定目录./configure --prefix=/usr/local/python3# 编译make && make install
查看软链接设置
xxxxxxxxxxls -al /usr/bin | grep python
可以看到python的链接是python2,所以直接执行python就相当于执行Python2
将原来 python 的软链接重命名或者删除
xxxxxxxxxxmv /usr/bin/python /usr/bin/python.bak# rm /usr/bin/python
将 python 链接至 python3
xxxxxxxxxxcd /usr/local/python3ln -s /usr/local/python3/bin/python3 /usr/bin/pythonln -s /usr/local/bin/pip3 /usr/bin/pip
验证版本
xxxxxxxxxxpython -Vpip -V
升级 Python 之后,由于将默认的 python 指向了 python3,yum 不能正常使用,需要编辑 yum 的配置文件。
用vi打开以下两个文件:
xxxxxxxxxxvi /usr/bin/yumvi /usr/libexec/urlgrabber-ext-down
将 #!/usr/bin/python 修改为 #!/usr/bin/python2.7,按esc后,输入:wq,保存退出。
在安装python3的时候遇到了这个问题,解决办法如下:
安装GCC软件套件
xxxxxxxxxxyum -y install gcc
gcc是linux下的编译器,它可以编译 C,C++,Ada,Object C和Java等语言,利用它就可以生成可执行的二进制文件。
查看gcc版本 : gcc -v
configure是一个shell脚本,它可以自动设定源程序以符合各种不同平台上Unix系统的特性,并且根据系统叁数及环境产生合适的Makefile文件或是C的头文件(header file),让源程序可以很方便地在这些不同的平台上被编译连接。
1、configure,这一步一般用来生成 Makefile,为下一步的编译做准备,你可以通过在 configure 后加上参数来对安装进行控制,比如代码:./configure --prefix=/usr 意思是将该软件安装在 /usr 下面,执行文件就会安装在 /usr/bin (而不是默认的 /usr/local/bin),资源文件就会安装在 /usr/share(而不是默认的/usr/local/share)。同时一些软件的配置文件你可以通过指定 –sys-config= 参数进行设定。有一些软件还可以加上 –with、–enable、–without、–disable 等等参数对编译加以控制,你可以通过允许 ./configure –help 察看详细的说明帮助。
2、make,这一步就是编译,大多数的源代码包都经过这一步进行编译(当然有些perl或python编写的软件需要调用perl或python来进行编译)。如果 在 make 过程中出现 error ,你就要记下错误代码(注意不仅仅是最后一行),然后你可以向开发者提交 bugreport(一般在 INSTALL 里有提交地址),或者你的系统少了一些依赖库等,这些需要自己仔细研究错误代码。
3、make insatll,这条命令来进行安装(当然有些软件需要先运行 make check 或 make test 来进行一些测试),这一步一般需要你有 root 权限(因为要向系统写入文件)。
在Linux下安装一个应用程序时,一般先运行脚本configure,然后用make来编译源程序,在运行make install,最后运行make clean删除一些临时文件。使用上述三个自动工具,就可以生成configure脚本。运行configure脚本,就可以生成Makefile文件,然后就可以运行make、make install和make clean。
新开会话窗口生效,重启后也失效。 格式:hostname 主机名称
xxxxxxxxxx[root@wangzy ~]# hostname XXXX
新开会话窗口生效,重启后仍旧生效。 格式:hostnamectl set-hostname 主机名称
xxxxxxxxxx[root@wangzy ~]# hostnamectl set-hostname XXXX
重启后生效,新开窗口不生效
xxxxxxxxxx[root@wangzy ~]# vi /etc/hostname
rpm命令是Red-Hat Package Manager(RPM软件包管理器)的缩写, 该命令用于管理Linux 下软件包的软件。在 Linux 操作系统下,几乎所有的软件均可以通过RPM 进行安装、卸载及管理等操作。
概括的说,rpm命令包含了五种基本功能:安装、卸载、升级、查询和验证。
语法格式:rpm [参数] [软件包]
| -a | 查询所有的软件包 |
|---|---|
| -b或-t | 设置包装套件的完成阶段,并指定套件档的文件名称; |
| -c | 只列出组态配置文件,本参数需配合”-l”参数使用 |
| -d | 只列出文本文件,本参数需配合”-l”参数使用 |
| -e或--erase | 卸载软件包 |
| -f | 查询文件或命令属于哪个软件包 |
| -h或--hash | 安装软件包时列出标记 |
| -i | 显示软件包的相关信息 |
| --install | 安装软件包 |
| -l | 显示软件包的文件列表 |
| -p | 查询指定的rpm软件包 |
| -q | 查询软件包 |
| -R | 显示软件包的依赖关系 |
| -s | 显示文件状态,本参数需配合”-l”参数使用 |
| -U或--upgrade | 升级软件包 |
| -v | 显示命令执行过程 |
| -vv | 详细显示指令执行过程 |
直接安装软件包
xxxxxxxxxx[root@linuxcool ~]# rpm -ivh packge.rpm
忽略报错,强制安装
xxxxxxxxxx[root@linuxcool ~]# rpm --force -ivh package.rpm
列出所有安装过的包
xxxxxxxxxx[root@linuxcool ~]# rpm -qa
查询rpm包中的文件安装的位置
xxxxxxxxxx[root@linuxcool ~]# rpm -ql ls
卸载rpm包
xxxxxxxxxx[root@linuxcool ~]# rpm -e package.rpm
升级软件包
xxxxxxxxxx[root@linuxcool ~]# rpm -U file.rpm
ifconfig -a 或者 ip addr
1.查看哪个包提供了ifconfig命令:yum search ifconfig 或者 yum provides ifconfig
2.可以看到net-tools包提供ifconfig包安装net-tools包,执行安装命令:yum install net-tools
lsof -i:8080 或者 netstat -tunlp | grep 8080
Linux 服务管理两种方式service和systemctl
systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
即systemctl也会去/etc/init.d目录下,查看,执行相关程序。
启动一个服务:systemctl start firewalld.service 关闭一个服务:systemctl stop firewalld.service 重启一个服务:systemctl restart firewalld.service 显示一个服务的状态:systemctl status firewalld.service 在开机时启用一个服务:systemctl enable firewalld.service 在开机时禁用一个服务:systemctl disable firewalld.service 查看服务是否开机启动:systemctl is-enabled firewalld.service 查看已启动的服务列表:systemctl list-unit-files|grep enabled 查看启动失败的服务列表:systemctl --failed
CentOS 7.0默认使用的是firewall作为防火墙
查看firewall是否运行
systemctl status firewalld 或者 firewall-cmd --state
关闭、开启、重启
systemctl stop firewalld
systemctl start firewalld
systemctl restart firewalld
禁止firewall开机启动(默认开机启动) systemctl disable firewalld
查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd--get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
查看当前开了哪些服务
其实一个服务对应一个端口,每个服务对应/usr/lib/firewalld/services下面一个xml文件。
firewall-cmd --list-services
查看还有哪些服务可以打开
firewall-cmd --get-services
xxxxxxxxxxfirewall-cmd --zone=public --add-port=80/tcp --permanent
从100到500这之间的端口我们全部要打开
xxxxxxxxxxfirewall-cmd --zone=public --add-port=100-500/tcp --permanent
注意:--permanent永久生效,没有此参数重启后失效。
firewall-cmd --reload
xxxxxxxxxxfirewall-cmd --zone=public --query-port=80/tcp
firewall-cmd --zone=public --remove-port=80/tcp --permanent
开放http服务
xxxxxxxxxxfirewall-cmd --permanent --add-service=http
"/etc/hosts" 是Linux的本地静态主机名查询表,负责 Linux 系统中IP地址与域名快速解析的文件;
简单理解它就是个电脑本机的“IP地址 <-> 域名”的对应表,系统或任何软件都会优先检查hosts里面有没有对应的配置,之后才会去查询网络上的DNS服务器。
hosts 文件的格式为: IP地址 主机名/域名
重启网卡后生效。
getenforce
/usr/sbin/sestatus -v 如果SELinux status参数为enabled即为开启状态
/etc/selinux/config
进入网卡配置文件目录
xxxxxxxxxxcd /etc/sysconfig/network-scripts
ifconfig获取网卡名称ens33
xxxxxxxxxxifconfig -a
查找对应的网卡文件
xxxxxxxxxxll *ens33*
编辑配置文件
xxxxxxxxxxvi ifcfg-ens33# 修改网卡类型,dhcp为自动获取、static为静态IP、none为禁用网卡BOOTPROTO='static'# 静态IP时增加3项IPADDR=192.168.1.200GATEWAY=192.168.1.1PREFIX=24# DNS解析(选填)DNS1=114.114.114.114
设置为“BOOTPROTO=‘static’”(如设置为none则禁用网卡,static则启用静态IP地址,设置为dhcp则为开启DHCP服务),并修改其他选项。
NM_CONTROLLED=no和ONBOOT=yes可根据您的需求进行设置。 NM_CONTROLLED是network manger的参数,实时生效,修改后无需要重启网卡立即生效。 ONBOOT=yes 开机自启动网卡。
如需DNS解析服务,则可以在配置网卡文件时加入DNS1、DNS2等等,或修改 “/etc/resolv.conf”文件。
xxxxxxxxxx# vim /etc/resolv.confnameserver 114.114.114.114
重启网卡
xxxxxxxxxxsystemctl restart network
注意事项:
配置动态IP地址时,只需修改“BOOTPROTO=、ONBOOT=”选项 配置静态IP地址时,只需修改“BOOTPROTO=、ONBOOT=”选项, 并添加“IPADDR=、GATEWAY=、PREFIX=”选项 其他选项若没需求最好不要改,不然容易造成重启网卡失败。
| TYPE=Ethernet | 类型 |
|---|---|
| BOOTPROTO=none | 设置为none禁止DHCP,设置为static启用静态IP地址,设置为dhcp开启DHCP服务 |
| NETMASK=255.255.255.0 | 子网掩码 |
| PREFIX = 24 | 子网掩码 |
| PEERDNS | 是否允许DHCP获得的DNS覆盖本地的DNS |
| PEERROUTES | 是否从DHCP服务器获取用于定义接口的默认网关的信息的路由表条目 |
| UUID | 唯一标识 |
| GATEWAY= | 设置网关 |
| IPV6INIT=no | 禁止IPV6 |
| IPV4_FAILURE_FATAL=yes | 如果ipv4配置失败禁用设备 |
| IPV6_FAILURE_FATAL=yes | 如果ipv6配置失败禁用设备 |
| NAME=“eth 或 ens” | 定义设备名称 |
| BROADCAST=“address” | address表示广播地址 |
| MACADDR=“MAC-address” | MAC-address表示指定一个MAC地址 |
| USERCTL=yes/no | 是否允许非root用户控制该设备 |
| ONBOOT= | 是否开机自启 |
| DNS1= | DNS解析服务 |
| IPADDR= | 静态IP地址 |
| GATEWAY= | 网关 |
=======================================================================================
1.先用 pip list 命令显示已安装包的信息(包名与版本号);
2.再用 pip show 包的名字 命令能显示包的安装路径。
一般在此目录下:"/usr/local/python3\python3.7\lib\site-packages"
xxxxxxxxxxpip3 install uwsgi# 增加软连接ln -s /usr/local/python3/bin/uwsgi /usr/local/bin/uwsgi# 启动 uwsgi 配置文件方式uwsgi --ini myweb_uwsgi.ini
测试uwsgi,创建test.py文件
xxxxxxxxxxdef application(env, start_response):start_response('200 OK', [('Content-Type','text/html')])return [b"Hello World"]
通过uwsgi运行该文件
xxxxxxxxxxuwsgi --http :8001 --wsgi-file test.py
=====================================================================================
xxxxxxxxxxpython -m django --version
xxxxxxxxxxpip install django
xxxxxxxxxxpip install django==1.11.29 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
我们可以通过 “ pip show 包名称 ” ,来查看部分的信息,只能大致的了解到包被安装在python安装目录下的lib\site-packages目录下。
xxxxxxxxxxln -s /usr/local/python3/lib/python3.7/site-packages/django/bin/django-admin.py /usr/local/bin/django-admin
打开命令行,cd 到一个你想放置你代码的目录,然后运行以下命令:
xxxxxxxxxxdjango-admin startproject myweb
这行代码将会在当前目录下创建一个 myweb 目录。
xxxxxxxxxxmyweb/manage.pymyweb/__init__.pysettings.pyurls.pywsgi.py
最外层的:file: myweb/ 根目录只是你项目的容器, Django 不关心它的名字,你可以将它重命名为任何你喜欢的名字。
manage.py: 一个让你用各种方式管理 Django 项目的命令行工具。
里面一层的 myweb/ 目录包含你的项目,它是一个纯 Python 包。它的名字就是当你引用它内部任何东西时需要用到的 Python 包名。
__init__.py:一个空文件,告诉 Python 这个目录应该被认为是一个 Python 包。
urls.py:Django 项目的 URL 声明,就像你网站的“目录”。
wsgi.py:作为你的项目的运行在 WSGI 兼容的Web服务器上的入口。
请切换到创建项目的目录myweb,然后运行下面的命令:
xxxxxxxxxxpython manage.py runserver
xxxxxxxxxx# 正常提示August 31, 2021 - 09:11:58Django version 1.11.29, using settings 'web.settings'Starting development server at http://127.0.0.1:8000/Quit the server with CONTROL-C.
默认情况下,runserver 命令会将服务器设置为监听本机内部 IP 的 8000 端口;若修改端口为:8080
xxxxxxxxxxpython manage.py runserver 8080
请确定你现在处于 manage.py 所在的目录下,然后运行这行命令来创建一个应用app1
xxxxxxxxxxpython manage.py startapp app1
xxxxxxxxxxapp1/__init__.pyadmin.pyapps.pymigrations/__init__.pymodels.pytests.pyviews.py
打开 app1/views.py,把下面这些 Python 代码输入进去:
xxxxxxxxxxfrom django.http import HttpResponsedef index(request):return HttpResponse("Hello, world. You're at the app1 index.")
这是 Django 中最简单的视图。如果想看见效果,我们需要将一个 URL 映射到它——这就是我们需要 URLconf 的原因了。
为了创建 URLconf,请在 app1 目录里新建一个 urls.py 文件。你的应用目录现在看起来应该是这样:
xxxxxxxxxxapp1/__init__.pyadmin.pyapps.pymigrations/__init__.pymodels.pytests.pyurls.py # 新建此文件views.py
在 app1/urls.py 中,输入如下代码
Django==1.11.0导入url方式
xxxxxxxxxxfrom django.conf.urls import url
Django==2.0导入url方式
xxxxxxxxxxfrom django.urls import pathfrom . import viewsurlpatterns = [path('', views.index, name='index'),]
下一步是要在根 URLconf 文件中指定我们创建的 app1.urls 模块。在 myweb/urls.py 文件的 urlpatterns 列表里插入一个 include(), 如下:
Django==1.11.0导入include方式
xxxxxxxxxxfrom django.contrib import adminfrom django.conf.urls import url,include # django1.11urlpatterns = [url('app1/', include('app1.urls')),url('admin/', admin.site.urls),]
Django==2.0导入include方式
xxxxxxxxxxfrom django.contrib import adminfrom django.urls import path, include # django2.0urlpatterns = [path('app1/', include('app1.urls')),path('admin/', admin.site.urls),]
函数 include() 允许引用其它 URLconfs。每当 Django 遇到 :func:~django.urls.include 时,它会截断与此项匹配的 URL 的部分,并将剩余的字符串发送到 URLconf 以供进一步处理。
我们设计 include() 的理念是使其可以即插即用。因为投票应用有它自己的 URLconf( app1/urls.py ),他们能够被放在 "/app1/" , "/fun_app1/" ,"/content/app1/",或者其他任何路径下,这个应用都能够正常工作。
当包括其它 URL 模式时你应该总是使用 include() , admin.site.urls 是唯一例外。
xxxxxxxxxxpython manage.py runserver
用你的浏览器访问 "http://localhost:8000/app1/",你应该能够看见 "Hello, world. You're at the polls index." ,这是你在 index 视图中定义的。
======================================================================================
xxxxxxxxxxyum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
让 Nginx 支持 Rewrite 功能;PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。
xxxxxxxxxxyum install -y pcre pcre-devel
xxxxxxxxxx#下载wget https://nginx.org/download/nginx-1.21.1.tar.gztar -zxvf nginx-1.21.1.tar.gz#创建安装目录mkdir /usr/local/nginxcd nginx-1.21.1#编译安装./configure --prefix=/usr/local/nginxmake && make install#开启、查看版本[root@hxj]# /usr/local/nginx/sbin/nginx[root@hxj]# nginx -v
添加源
xxxxxxxxxxsudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装nginx
xxxxxxxxxxsudo yum -y install nginx
进入到安装的目录里面 whereis nginx
进入该路径:cd /usr/local/nginx/sbin
启动nginx 命令: ./nginx 出现下面启动成功
查看nginx 的状态:
ps -aux | grep nginx 或者 ps -ef | grep nginx
出现master 则启动成功。
关闭nginx 命令 kill -9 8725(进程号上面的) 则关闭nginx
停止 nginx 命令:./nginx -s stop 或者 ./nginx -s quit
重启nginx命令:./nginx -s reload
查看linux 开放的所有端口:netstat -ntpl
重启网络服务命令 :systemctl restart network 或者 service network restart
总结:
从容停止Nginx: kill -QUIT 主进程号
例如:kill -QUIT 16391
快速停止Nginx: kill -TERM 主进程号
强制停止Nginx: kill -9 主进程号
注意:通过IP即可访问,nginx默认页面;防火墙是否关闭。
启动nginx的命令为 /usr/local/nginx/sbin/nginx
停止nginx的命令为 /usr/local/nginx/sbin/nginx -s stop
重启nginx的命令为 /usr/local/nginx/sbin/nginx -s reload
可以看得出来,很麻烦,每次都要把nginx的启动问文件的路径写出来。所以我们可以配置一个systemctl 命令来方便操作nginx的启动、停止和重启命令。
linux服务目前主要有service和systeectl两种管理方式,systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程,尽可能更多进程并发启动,
所以设置nginx启动命令就有两种方案
在 /usr/lib/systemd/system/目录下面新建一个nginx.service文件。并赋予可执行的权限。
xxxxxxxxxxvim /usr/lib/systemd/system/nginx.service
若权限不足时:
xxxxxxxxxxchmod +x /usr/lib/systemd/system/nginx.service# 或者chmod 755 /usr/lib/systemd/system/nginx.service
xxxxxxxxxx[Unit]Description=nginx - high performance web serverAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.confExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confExecReload=/usr/local/nginx/sbin/nginx -s reload# ExecStop=/usr/local/nginx/sbin/nginx -s quitExecStop=/usr/local/nginx/sbin/nginx -s stopPrivateTmp=true[Install]WantedBy=multi-user.target
启动前,记得把之前的先关闭(kill -9 进程号);在启动服务之前,需要先重载systemctl命令。
xxxxxxxxxxsystemctl daemon-reload // 重载系统服务systemctl start nginx // 开启服务systemctl stop nginx // 停止服务systemctl restart nginx // 重新启动systemctl status nginx // 查看状态systemctl enable nginx // 设置开机自启动systemctl disable nginx // 停止开机自启动systemctl is-enabled nginx // 是否开机自启动systemctl list-units --type=service // 查看所有已启动的服务
发现启动还是出现了问题。用systemctl status nginx.service 来查看问题所在。
service命令其实是去/etc/init.d目录下,去执行相关程序,相应脚本需要自己编写。
安装nginx后,使用命令service nginx start启动nginx服务是,无法启动,会报错误。
这是因为服务器未设置nginx启动脚本,那么需要在/etc/init.d/目录下创建nginx的启动文件。
步骤:
1.执行 vi /etc/init.d/nginx
2.进入文件,将以下内容复制到nginx文件,并保存。
xxxxxxxxxx#!/bin/bash#Startup script for the nginx Web Server#chkconfig: 2345 85 15nginx=/usr/local/nginx/sbin/nginxconf=/usr/local/nginx/conf/nginx.confcase $1 instart)echo -n "Starting Nginx"$nginx -c $confecho " done.";;stop)echo -n "Stopping Nginx"killall -9 nginxecho " done.";;test)$nginx -t -c $confecho "Success.";;reload)echo -n "Reloading Nginx"ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUPecho " done.";;restart)$nginx -s reloadecho "reload done.";;*)echo "Usage: $0 {start|restart|reload|stop|test|show}";;esac
3.执行 service nginx start后报无权限错误,这时候需要处理文件权限。
4.执行 chmod 755 nginx即可。
service nginx start 启动
service nginx stop 关闭
servcie nginx reload 重新加载
1、编辑/etc/profile
2、在最后一行添加配置
3、使配置立即生效
xxxxxxxxxxvim /etc/profileexport PATH=$PATH:/usr/local/nginx/sbinsource /etc/profile
1.打开 /etc/nginx/conf.d/文件夹,创建配置文件xxx.conf,内容如下
xxxxxxxxxxserver {listen 80;server_name **.106.2**.175;location / {root /public/app/dist;index index.php index.html index.htm;}location /sell {proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Host $http_host;proxy_set_header X-NginX-Proxy true;proxy_pass http://127.0.0.1:8080;proxy_redirect off;}}
2.在 /etc/nginx/nginx.conf文件中有一行就是把刚刚配置的引进总的nginx配置中
xxxxxxxxxxinclude /etc/nginx/conf.d/*.conf;3.配置完成后重新启动nginx
xxxxxxxxxxnginx -t # 查看nginx状态nginx -s reload # 重新载入配置文件nginx -s reopen # 重启 Nginxnginx -s stop # 停止 Nginx
xxxxxxxxxx#创建 Nginx 运行使用的用户 www/usr/sbin/groupadd www/usr/sbin/useradd -g www www#设置包含多个配置文件,在nginx.conf底部添加include vhost/*.conf;#启动/usr/local/webserver/nginx/sbin/nginx/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件/usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx/usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx# /usr/local/webserver/nginx/conf/vhost/demo.tilesrow.com.confserver{listen 80;#listen [::]:80;server_name xx.com;index index.html index.htm index.php default.html default.htm default.php;root /data/project/demo1;access_log /usr/local/webserver/nginx/logs/xx.com.log;}
内网映射端口配置
xxxxxxxxxxserver{listen 80;#listen [::]:80;server_name demo.xx.com;location / {proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Host $http_host;proxy_redirect off;proxy_pass http://127.0.0.1:8001;}access_log /usr/local/webserver/nginx/logs/demo.xx.com.log;}
先在 Django 项目根目录下新建一个 uWSGI 的配置文件myweb_uwsgi.ini,与manage.py同级
xxxxxxxxxxproject_web/├── manage.py├── myweb/│ ├── __init__.py│ ├── settings.py│ ├── urls.py│ └── wsgi.py└── myweb_uwsgi.ini
xxxxxxxxxx[uwsgi]socket = :8081chdir = /home/setup/project_mywebmodule = myweb.wsgimaster = trueprocesses = 4vacuum = true
module = myweb.wsgi 可以这么来理解。对于 myweb_uwsgi.ini 文件而言,与它同级目录有一个 myweb 目录,这个目录下有一个 wsgi.py 文件。接下来,通过 uwsgi 命令读取 myweb_uwsgi.ini 文件启动项目
xxxxxxxxxxuwsgi --ini myweb_uwsgi.ini
注意查看uwsgi的启动信息,如果有错,就要检查配置文件的参数是否设置有误。
最主要的就是这前两行配置:
xxxxxxxxxxlocation / {include uwsgi_params;uwsgi_pass 127.0.0.1:8081;uwsgi_connect_timeout 2;}
include 必须指定为 uwsgi_params。而 uwsgi_pass 指的是本机 IP 和端口号,并且要与 myweb_uwsgi.ini 配置文件中的 IP 和端口号必须保持一致。
现在重新启动 nginx,然后浏览器访问 127.0.0.1。
在 uWSGI 后台就可以看到有信息输出。通过 IP 和端口号的指向,请求应该是先到 nginx 的,如果你在页面上执行一些请求,就会看到,这些请求最终会转到 uwsgi 来处理。
最后我们将 uWSGI 配置为开机自启
打开 sudo vi /etc/rc.local 将
xxxxxxxxxxuwsgi --ini /home/steup/myweb/uwsgi.ini &
添加到文件中。
注意要添加到 exit 0 之前,& 表示该服务是在后台执行。
django创建的项目中去修改 setting.py 文件:
ALLOWED_HOSTS = ['*'] #在这里请求的host添加了*
======================================================================================
======================================================================================
mkdir [-mp] 目录名
rm [-rf] 目录名/文件
-f, --force 忽略不存在的文件,从不给出提示。
-r, -R, --recursive 指示rm将参数中列出的全部目录和子目录均递归地删除。
rm -rf * 删除当前目录下的所有文件,这个命令很危险,应避免使用。
grep -Ev "^$|#" old_file_name > new_file_name
-E 使用正则表达示进行匹配
-i 忽略大小写
-v 反选
-n 输出满足条件字符串所在行的行号
^ 开头匹配
$ $结尾匹配;^$表示匹配空行。
| 正则的或运算
^$|#,表示空行或#开头的行(注释行)
命令:ls -lh 或者 ll -h
linux系统中清空文件内容的三种方法:
修改用户和组
命令:chown 用户:用户组 filename
读写执行权限
命令:chmod 777 filename
语法: ln -s 源文件 目标文件
创建软链接,如果不带 -s 参数,创建硬链接。
命令:ps -ef | grep 进程关键字
=======================================================================================
xxxxxxxxxxC:\Windows\System32\drivers\etc\hosts