Nginx 命令

nginx + 反向代理 + runserver

location / {
           proxy_pass http://www.pipixia957.cn:8000;  #反向代理设置
           proxy_set_header X-real-ip $remote_addr;
           proxy_set_header Host $http_host;
        }


[uwsgi]
http=0.0.0.0:8000
chdir=/home/ubuntu/pro/project
wsgi-file=project/wsgi.py
processes=2
threads=2
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log

runserver启动
#访问不需要加端口

poechant@ubuntu:sudo ./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

nginx + uwsgi启动

 location / {
            include uwsgi_params;
            uwsgi_pass www.pipixia957.cn:8000;
        }

[uwsgi]
socket=0.0.0.0:8000
chdir=/home/ubuntu/pro/project
wsgi-file=project/wsgi.py
processes=2
threads=2
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log

#访问不需要再加端口

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

nginx静态文件配置

location /static{
            alias  /var/www/myApp/static;
        }
sudo mkdir -vp /var/www/myApp/static/
sudo chmod 777 /var/www/myApp/static/

#工程目录settings下配置静态文件
STATIC_ROOT = '/var/www/myApp/static'
STATIC_URL = '/static/'

#迁移静态文件
python manage.py collectstatic

#settings目录中
DEBUG = Flase
ALLOW_HOST = ['*']

[root@centos-1-22 sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos-1-22 sbin]# ./nginx -h
nginx version: nginx/1.0.15
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

nginx + 负载均衡

upstream mycom{
    ip_hash;
    server 10.11.0.1:8000;  #负载均衡服务器群
    server 10.11.0.1:8000;
    server 10.11.0.1:8000  down;
}

location / {   
            include uwsgi_params;
            uwsgi_pass mycom; #连接负载均衡服务器
        }
  1. 显示帮助信息

 

或者:

上述是采用向 Nginx 发送信号的方式,或者使用:

  1. 指定配置文件
  1. 启动 Nginx          /usr/local/nginx/sbin/nginx

另一种显示的是详细的版本信息:

金沙官网线上,poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -t
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
2012/01/09 16:45:09 [emerg] 23898#0: open() "/usr/local/nginx/logs/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

  1. Nginx 重载配置
  1. 停止 Nginx

有两种可以查看 Nginx 的版本信息的参数。第一种如下:

如果显示如上,则表示配置文件正确。否则,会有相关提示。

本文由金沙官网线上发布于操作系统,转载请注明出处:Nginx 命令

您可能还会对下面的文章感兴趣: