首页 > 编程知识 正文

web服务器和应用服务器的区别(javaweb项目部署到服务器)

时间:2023-05-03 15:14:07 阅读:65225 作者:1985

文章目录1 .看图说话2 .开始部署django3.遇到的漏洞4 .声明

#前几天我按照文档去了,也记录了操作过程,其实挖了很多洞,没通过。 又受了几天的折磨,终于在ubuntu成功地运行了德江非政府组织。 记录如下

1 .看图说话

首先,使用django web开发框架。 (因为我不会html、css、js等,所以有了便于使用的开发框架,就能轻松开发,部署也很简单。 ) django使用python作为开发语言,在开发完成后作为web APP应用程序在web服务器上运行,但我们选择的web服务器例如Nginx、uWSGI不识别python,因此web APP应用程序通信标准WSGIuWSGI必须是实现WSGI协议、uwsgi、http等协议的web服务器。 选择uwsgi服务器并运行django,然后使用wsgi协议与他们进行通信。 另外,为了提高网页的响应效率,采用了利用Nguinx服务处理/响应静态页面、利用uWSGI服务响应动态页面等网页运动分析对策。 为了得到动静分离的效果,安装了nginx。 两个web服务器(nginx和uWSGI )需要通信才能协同工作,他们的通信可以通过套接字实现。 在这两个服务器上运行的web服务器实际上是两个可执行文件。 要在他们之间进行相互调用/通信,一种方法叫做套接字。 也就是说,如果用户的浏览器面向服务器侧,则通过http协议与nginx进行通信,nginx处理静态请求/响应,并且将动态请求/响应传递给uWSGI。 uWSGI调用python程序(django )处理请求并返回处理结果。 开始部署django step1:

安装conda以安装django web开发框架的用户的主要python和pip都支持。 本文的python和pip3均为/usr/舒适老师中的可执行程序#python和pip兼容错误调用可能出现数据包错误的现象pip3安装django #为django-admin.pystartppo 创建项目访问验证mysite是否成功安装的项目文件/usr/舒适老师/python3runserver0.0.0. 0:8000 # 8000端口测试django 小火箭uWSGI web服务器pip 3安装uwsgi安装验证uwsgi是否成功安装vimtest.pydefapplication(env, 将显示start_response ) : start _ re sponsion [ (' content-type ', (文本/html ) ) ) return ) b'helloworld ) ) python3# return (hello world ) ) python2uw SGI-- http 33608000-world ) PostgreSQL数据库安装和数据库操作接口#安装数据库sudo apt-getinstallpostgresql-client #安装完成后,数据库超级用户密码为空的pip3 install psycopg2-验证舒适老师Ary#psycopg2是否正常安装/usr/舒适老师/python3importpsycopg2dir (psyco pg2) nging nginx可隔离负责静态网页处理的动作,提高页面响应效率安装sudo apt-get install nginx #后,nginx会自动检查nginxsudo service nginx status# 访问浏览器以启用欢迎界面127.0.0.1:80#,或启用stop、restart nginx init.d/nginx开始| stop|restart 假设修改损害nginx的配置文件cd mysite #进入mysite顶级项目文件夹# uw SGI---http :8000---module my site.wsgi # 如果可以的话,恭喜你。 你实现了以上图像的内容。 建议使用# uwsgivimmysite _ uw SGI.ini [ uw SGI ] # django-related settings # thebasedirectory (全路径) chdir=/。 django ' swsgifilemodule=my site.wsgi :应用程序# thevirtualenv (全路径) ) optional ) home=/path/to/virtuaal

processesprocesses = 4# the socket (use the full path to be safesocket = 127.0.0.1:8001# ... with appropriate permissions - may be needed# chmod-socket = 664# clear environment on exitvacuum = true# background the processdaemonize=/path/to/mysite/mysite.log #后台运行uwsgi服务器pidfile=/path/to/mysite/mysite.pid #储存uwsgi运行时的pid,可以用于终止uwsgi服务器 #启动web服务器uwsgi --ini /path/to/mysite_uwsgi.ini#查看服务ps -aux |grep "uwsgi"#访问你自己的项目127.0.0.1:8000 #注意我们设置nginx监听的端口是8000,而8001端口是nginx与uWSGI通信的端口#停止uwsgi --stop /path/to/mysite/mysite.pid或者sudo pkill -f uwsgi -9 3.遇到的坑 apache2与nginx重复安装,重复卸载,最后两个web服务器懂启动不了,好吧!最后卸载apache2,apt安装nginx $ which nginx/usr/s舒服的老师/nginx #我也不知道为啥到s舒服的老师里面去了$ sudo /usr/s舒服的老师/nginx -t #测试nginx的配置文件等是否正确,而且会告诉你配置文件位置$ sudo /usr/s舒服的老师/nginx #启动nginx$ ps -aux |grep "nginx" #验证nginx启动成功$ sudo /usr/s舒服的老师/nginx -s stop #显将nginx停了,我们要去修改配置文件 nginx配置文件的坑 $ sudo /usr/s舒服的老师/nginx -t 告诉我nginx配置文件在/etc/nginx/conf.d/*.conf ;有些人的配置文件在/etc/nginx/sites-enabled/文件夹里 #如果配置文件在/etc/nginx/sites-enbled,操作如下#create /etc/nginx/sites-available/ directory and put this in it#sites-available文件夹包括一些可配置文件#sites-enabled文件夹包括一些已经配置了的文件#最好不要修改nginx.conf文件#在sites-available文件夹创建mysite_nginx.conf文件并写入如下内容---------------------------------------------------------------------------------------------------------# mysite_nginx.conf# the upstream component nginx needs to connect toupstream django { # server unix:///path/to/your/mysite/mysite.sock; # for a file socket server 127.0.0.1:8001; # for a web port socket (we'll use this first) nginx与uWSGI通信使用8001端口}# configuration of the serverserver { # the port your site will be served on listen 8000; #nginx监听8000端口 # the domain name it will serve for server_name 172.XXX.XXX.XXX; # substitute your machine's IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /path/to/your/mysite/media; # your Django project's media files - amend as required } location /static { alias /path/to/your/mysite/static; # your Django project's static files - amend as required } # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; include /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed #/etc/nginx/uwsgi_params; }}----------------------------------------------------------------------------------------------------------------------------#symlink to this file from /etc/nginx/site-enabled so nginx can see itsudo ln -s /etc/nginx/sites-available/mysite_nginx.conf /etc/nginx/sites-enabled/#重启nginx服务sudo /etc/init.d/nginx restart 或者 sudo /usr/s舒服的老师/nginxps -aux |grep nginx #如果配置文件在/etc/nginx/conf.d/,操作如下-----------------------------------------------------------------------------------------------------# mysite_nginx.conf# the upstream component nginx needs to connect toupstream django { # server unix:///path/to/your/mysite/mysite.sock; # for a file socket server 127.0.0.1:8001; # for a web port socket (we'll use this first) nginx与uWSGI通信使用8001端口}# configuration of the serverserver { # the port your site will be served on listen 8000; #nginx监听8000端口 # the domain name it will serve for server_name 172.XXX.XXX.XXX; # substitute your machine's IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /path/to/your/mysite/media; # your Django project's media files - amend as required } location /static { alias /path/to/your/mysite/static; # your Django project's static files - amend as required } # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; include /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed #/etc/nginx/uwsgi_params; }}----------------------------------------------------------------------------------------------------------------------------#symlink to this file from /etc/nginx/conf.d/ so nginx can see itsudo ln -s /etc/nginx/sites-available/mysite_nginx.conf /etc/nginx/conf.d/#重启nginx服务sudo /etc/init.d/nginx restart 或者 sudo /usr/s舒服的老师/nginxps -aux |grep nginx nginx欢迎页面一直存在 #方法一sudo rm /etc/nginx/sites-enabled/default.conf#方法二修改default.conf中监听的端口,让默认监听的端口与刚才mysite-nginx.conf监听的端口不一样 uwsgi安装失败 有没有安装python-dev包? uwsgi调用失败 pip 是不是使用的conda安装的? 4.声明

纯粹用于记录,交流学习也是可行的,没有任何教学目的,请根据自己的实际情况操作自己的系统。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。