https://www.cnblogs.com/taiyonghai/p/6728707.html
https://www.cnblogs.com/taiyonghai/p/5610112.html
https://www.cnblogs.com/yangyh11/p/9801466.html
https://blog.51cto.com/13363488/2349546
nginx 使用最多的三个核心功能是反向代理、负载均衡和静态服务器
下载依赖
yum install -y gcc gcc-c++wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gzyum -y install make zlib zlib-devel libtool openssl openssl-devel
安装
```openssl
tar -zxvf openssl-fips-2.0.10.tar.gz cd openssl-fips-2.0.10 ./config && make && make install
pcre
tar zxvf pcre-8.40.tar.gz cd pcre-8.40 ./configure && make && make install
zlib
tar zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure && make && make install
nginx
tar zxvf nginx-1.10.2.tar.gz cd nginx-1.10.2 ./configure && make && make install
或
sudo apt-get install nginx
- 相关目录<br />nginx安装之后的文件结构大致为:- /etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下- 程序文件在/usr/sbin/nginx- 日志放在了/var/log/nginx中- 并已经在/etc/init.d/下创建了启动脚本nginx- 虚拟主机的目录设置在了/var/www> main:用于进行nginx全局信息的配置<br />events:用于nginx工作模式的配置<br />http:用于进行http协议信息的一些配置<br />server:用于进行服务器访问信息的配置<br />location:用于进行访问路由的配置<br />upstream:用于进行负载均衡的配置- 启动
whereis nginx
cd /usr/local/nginx/ /usr/local/ngix/sbin/nginx 或 sudo /etc/init.d/nginx start http://localhost
- 配置<br />进入 /etc/nginx/ 的 nginx.conf 查看路径 <br />进入 /etc/nginx/sites-enabled/<br />配置虚拟主机,负载均衡反向代理等 <br />基于域名的虚拟主机 <br />基于ip的虚拟主机
include /etc/nginx/conf.d/.conf; include /etc/nginx/sites-enabled/;
```upstream advertiser_server {server 127.0.0.1:8080 max_fails=1 fail_timeout=15s weight=5; # 两个tomcat 可以配权重server 127.0.0.1:8081 max_fails=1 fail_timeout=15s weight=5;}server {listen 80; # 监听80 端口server_name payapi.test.com advapi.test.com; # 域名charset utf-8;location / {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://advertiser_server; # 上面的upstream}}
server {listen 80;server_name api.kellychen.hh; #域名charset utf-8;location / {index index.html; #html网页存放的目录root /var/www/html;}}
server {#监听的ip和端口listen 192.168.8.43:80;#主机名server_name 192.168.8.43;charset utf-8;location / {index index.html;#html网页存放的目录root /var/www/html;}}
- 常见命令
./nginx -v # 查看版本./nginx # 启动./nginx -s stop./nginx -s quit./nginx -s reload
查看配置文件目录:nginx -t
