网站部署nginx--uwsgi

来源:互联网 发布:数控铣床软件与编程 编辑:程序博客网 时间:2024/06/05 07:18

网站代码写完之后就是项目部署,主要包括两个方面:


1.nginx安装与配置:

1、Nginx 安装

系统平台:CentOS release 6.6 (Final) 64位。

一、安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

二、首先要安装 PCRE

PCRE 作用是让 Nginx 支持 Rewrite 功能。

1、下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

2、解压安装包:

[root@bogon src]# tar zxvf pcre-8.35.tar.gz

3、进入安装包目录

[root@bogon src]# cd pcre-8.35

4、编译安装 

[root@bogon pcre-8.35]# ./configure[root@bogon pcre-8.35]# make && make install

5、查看pcre版本

[root@bogon pcre-8.35]# pcre-config --version

安装 Nginx

1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz

[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

2、解压安装包

[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz

3、进入安装包目录

[root@bogon src]# cd nginx-1.6.2

4、编译安装

[root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35[root@bogon nginx-1.6.2]# make[root@bogon nginx-1.6.2]# make install

5、查看nginx版本

[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v

到此,nginx安装完成。


2.nginx配置:

首先,进入文件 cd /usr/local/nginx/conf/nginx.conf 编辑带入如下:


#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    #                  '$status $body_bytes_sent "$http_referer" '    #                  '"$http_user_agent" "$http_x_forwarded_for"';    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {        listen       80;        server_name  www.itcast.cn;        #charset koi8-r;        #access_log  logs/host.access.log  main;#        location / {#            root   html;#            index  index.html index.htm;#        }#根目录,注意html文件location / {root /var/www/ihome/static/html;index index.html;}#uwsgi配置iplocation /api {uwsgi_pass 127.0.0.1:5000;include uwsgi_params;}#静态文件配置,静态文件需要迁移到此文件下location /static {alias /var/www/ihome/static;}        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #location ~ \.php$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #    #server {    #    listen       443 ssl;    #    server_name  localhost;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_cache    shared:SSL:1m;    #    ssl_session_timeout  5m;    #    ssl_ciphers  HIGH:!aNULL:!MD5;    #    ssl_prefer_server_ciphers  on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}

注:需要拷贝static文件  :cp -r static /var/www/ihome/static

配置好uwsgi后启动nginx:sudo sbin/nginx

如需停止:sudo sbin/nginx -s stop


2.uwsgi文件创建与配置


1.进入虚拟环境:workon 虚拟环境名称

2.创建文件:touch uwsgi.ini

3.编辑文件:

[uwsgi]
#按照实际情况改动,这里只是举例# uwsgi 启动时所使用的地址与端口socket = 127.0.0.1:8001pidfile = uwsgi.piddaemonize = uwsgi.log# 指向网站目录chdir = /home/python/Desktop/ihome/test4# python 启动程序文件wsgi-file = test4.py# python 程序内用以启动的 application 变量名callable = app# 处理器数processes = 4# 线程数threads = 2#每次修改代码自动reload,无需要手动重启#py-autoreload = 1#状态检测地址stats = 127.0.0.1:9001

4.启动uwsgi:   uwsgi  --ini uwsgi.ini

5.启动nginx

如需关闭uwsgi:  uwsgi  --stop uwsgi.pid



原创粉丝点击