web 服务器 Nginx 的安装与配置
卸载老版本的 Nginx
- sudo apt-get --purge remove nginxsudo apt-get autoremove
- dpkg --get-selections|grep nginx// 将罗列出与 nginx 相关的软件, 如 nginx-common 一并删除 sudo apt-get --prege remove nginx-common1234
安装 Nginx
从官网下载 Nginx http://nginx.org/en/download.html
编译安装:
- tar -zxvf nginx-1.10.2.tar.gzcd nginx-1.10.2.tar.gz
- ./configure // 注意终端中的信息, 缺少库文件要记得安装在重新 configure 才行
- make
- sudo make install12345
Nginx 反向代理配置
一般一个反向代理建立一个. conf 文件, 在主配置文件 nginx.conf 中引入即可
- GGYun.conf
- server {
- listen 8001;
- server_name localhost;
- charset utf-8;
- access_log /home/codemap.access.log;
- location / {proxy_set_header X-Forwarded-For $remote_addr</span><span class="pun">;</span></code></li><li class="L9"><code><span class="pln"> proxy_set_header </span><span class="typ">Host</span><span class="pln"> $http_host;
- proxy_pass http://127.0.0.1:8000;
- }
- }12345678910
nginx.conf 文件中的部分配置
- worker_processes 4; // 进程数, 一般等于电脑 cpu 内核数 events {
- worker_connections 1024;// 最大链接数}
- http {// 配置文件根目录
- include mime.types;
- default_type application/octet-stream;
- sendfile on; #tcp_nopush on; #keepalive_timeout 0;
- keepalive_timeout 65; #gzip on;
- include codemap.conf;// 引入的配置文件}1234567891011121314
常用命令
重启 nginx:/usr/local/nginx/sbin/nginx -s reopen1 重新加载配置文件:/uar/local/nginx/sbin/nginx -s reload 1 启动:/uar/local/nginx/sbin/nginx1 关闭:/uar/local/nginx/sbin/nginx -s stop1
进程管理工具 supervisor 安装
服务器运行某个进程时可以用 supervisor 进行管理, 可以自动后台运行.
终端安装
apt-get install supervisor1
supervisor 配置
[program:GGYun]directory = /home/noah/Documents/src/github.com/HivenKay/GGYun // 项目路径 command = /home/noah/Documents/src/github.com/HivenKay/GGYun/GGYun // 可执行二进制文件路径 autostart = true // 是否制动启动 autorestart=true // 是否自动重启 startsecs = 5user = root // 执行用户 redirect_stderr = truestdout_logfile = /var/log/supervisord/GGYun.logstderr_logfile =/var/log/supervisord/ghost_err.log12345678910
supervisor 常用命令
supervisorctl start GGYun// 启动进程 1supervisorctl restart GGYun// 重启进程 1supervisorctl reload // 重启 supervisorctl1
supervisor 安装后可能遇到的问题
supervisorctl start GGYun 报错 unix:///var/run/supervisor.sock no such file
解决 https://github.com/Supervisor/supervisor/issues/480
sudo touch /var/run/supervisor.sock1sudo chmod 777 /var/run/supervisor.sock1sudo service supervisor restart1
连接远程服务器
windows 系统请安装 putty,linux 系统可以在终端直接链接
ssh root@139.196.180.208 //root 为用户名, 139.196.180.208 为服务器的 ip1
拷贝本地文件到服务器
scp /home/noah/Documents/... root@139.196.180.208:/home/noah/Documents/...
[3]supervisor 使用管理: 实现对异常中断子进程的自动重启 (以 nginx 和 apache 为例)
来源: http://www.bubuko.com/infodetail-2654526.html