Nginx

作者: 静心安分读书 | 来源:发表于2018-08-09 15:55 被阅读28次

一、介绍
Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的,是十分轻量级的 HTTP 服务器,它的发音为“engine X”。
Nginx功能丰富,可作为HTTP服务器,也可作为反向代理服务器,邮件服务器。支持FastCGI、SSL、Virtual Host、URL Rewrite、Gzip等功能。并且支持很多第三方的模块扩展。
ginx的稳定性、功能集、示例配置文件和低系统资源的消耗让他后来居上,在全球活跃的网站中有12.18%的使用比率,大约为2220万个网站。
二、安装
1、使用homebrew安装nginx
brew install nginx
2、安装成功提示信息:截取结尾

If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:PATH"' >> ~/.bash_profile For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/openssl/lib CPPFLAGS: -I/usr/local/opt/openssl/include ==> nginx Docroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. nginx will load all files in /usr/local/etc/nginx/servers/. To have launchd start nginx now and restart at login: brew services start nginx Or, if you don't want/need a background service you can just run: nginx ” 三、修改配置 安装路径:/usr/local/Cellar/nginx/ 配置路径:/usr/local/etc/nginx //一下两个貌似不需要 sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf error_log = /usr/local/var/log/php-fpm.log 四、启动 1、brew services start nginx 开启nginx,但是localhost:8080无法访问。 于是 brew services stop nginx 关闭。 2、再进入安装目录/usr/local/Cellar/nginx/1.15.2/bin 开启命令:./nginx 启动nginx,可以访问8080端口。 ![图片.png](https://img.haomeiwen.com/i9176693/0e2b00d54ab99886.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 3、报错:【Nginx】nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 就是没有权限, 4、使用sudo ./nginx 就开启了。。 五、关闭 网上并没有搜到有关合法关闭的方法,都是杀进程。。 1、ps -ef|grep nginx ps -ef|grep nginx
0 3210 1 0 二10上午 ?? 0:00.00 nginx: master process ./nginx
-2 3211 3210 0 二10上午 ?? 0:06.72 nginx: worker process
1105353028 80067 77564 0 4:18下午 ttys002 0:00.00 grep nginx
2、kill -QUIT 3210 或者 kill -9 nginx
3、重启
验证nginx配置文件是否正确
方法一:进入nginx安装目录bin下,输入命令./nginx -t
看到如下显示nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确!
输入命令./nginx -s reload 即可
方案二:kill -HUP pid
pid 是进程标识。如果想要更改配置而不需停止并重新启动服务,请使用该命令。在对配置文件作必要的更改后,发出该命令以动态更新服务配置。

对于重启,貌似还是查找进程,然后kill比较多吧?
六、常用命令
判断配置文件是否正确 sudo ./nginx -t

重新加载配置|重启|停止|退出 nginx

nginx -s reload|reopen|stop|quit
修改 nginx.conf 后,重载配置文件
sudo nginx -s reload
停止 nginx 服务器
sudo nginx -s stop

参考:https://yq.aliyun.com/articles/79214
https://www.cnblogs.com/codingcloud/p/5095066.html

七、配置
配置文件在/usr/local/etc/nginx/nginx.conf

结尾}之前添加
#}

upstream aaaa_pool{
server 127.0.0.1:8001;
server 127.0.0.1:8009;
}
#集团招采端口转发
server {
listen 80;
server_name aaaa.jj.com;
#access_log logs/book.log;
#error_log logs/book.error;

    #将所有请求转发给demo_pool池的应用处理
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://aaaa_pool;
    }
}

upstream bb_pool{
    server 127.0.0.1:8002;
}
 #绩效考核端口转发
  server {
      listen       80;
      server_name  bb-rating.jj.com;
      #access_log logs/book.log;
      #error_log logs/book.error;

      #将所有请求转发给demo_pool池的应用处理
      location / {
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_pass http://bb_pool;
      }
  }

upstream cc_pool{
server 127.0.0.1:8084 weight=2;
server 127.0.0.1:8085 weight=1;
}
#集团招采端口转发
server {
listen 80;
server_name localhost;
#access_log logs/book.log;
#error_log logs/book.error;

    #将所有请求转发给demo_pool池的应用处理
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://cc_pool;
    }
}

upstream dddd_biz{
    server 127.0.0.1:9081 weight=1;
}
#集团招采端口转发
server {
    listen       80;
    server_name  biz.dddd.jd.com;
    #access_log logs/book.log;
    #error_log logs/book.error;

    #将所有请求转发给demo_pool池的应用处理
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://dddd_biz;
    }
}

upstream eeee_ps{
    server 127.0.0.1:9080 weight=1;
}
#集团招采端口转发
server {
    listen       80;
    server_name  ps.eeee.jd.com;
    #access_log logs/book.log;
    #error_log logs/book.error;

    #将所有请求转发给demo_pool池的应用处理
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://ffff_ps;
    }
}

upstream ffff_biz_client{
server 127.0.0.1:9000 weight=1;
}
#集团招采端口转发
server {
listen 80;
server_name ffff.jd.com;
#access_log logs/book.log;
#error_log logs/book.error;

    #将所有请求转发给demo_pool池的应用处理
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://ffff_biz_client;
    }
}

include servers/*;
八、常用功能

相关文章

网友评论

    本文标题:Nginx

    本文链接:https://www.haomeiwen.com/subject/zpbxbftx.html