- 添加Nginx到YUM源
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
(会在 /etc/yum.repo.d/ 下生成一个nginx.repo)
- 安装Nginx
sudo yum install -y nginx
安装后的默认目录:
配置文件: /etc/nginx/nginx.conf
自定义的配置文件夹: /etc/nginx/conf.d
项目文件: /usr/share/nginx/html/
【default】
server {
# 当http协议被请求时,统一转发到https协议商
listen 80;
listen [::]:80; #IPV6协议
server_name domain.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
【image】
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /www/ssl/image.domin.gov.cn.pem; #证书文件
ssl_certificate_key /www/ssl/image.domin.gov.cn.key;
server_name image.domin.gov.cn;
#listen 80;
location / {
proxy_pass http://172.16.3.5/res/;
}
#plugin service
location /rabbitmq {
proxy_pass http://172.16.3.5:15672/;
}
location /kibana {
proxy_pass http://172.16.3.5:5601/app/kibana;
}
}
【web】
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /www/ssl/creditplatform.domin.gov.cn.pem; #证书文件
ssl_certificate_key /www/ssl/creditplatform.domin.gov.cn.key;
server_name creditplatform.domin.gov.cn;
# listen 80;
location / {
proxy_pass http://172.16.3.7:7070;
}
}
【website】
server{
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /www/ssl/www.domin.gov.cn.pem; #证书文件
ssl_certificate_key /www/ssl/www.domin.gov.cn.key;
server_name www.domin.gov.cn;
#listen 80;
charset utf-8;
location / {
root /usr/local/nginx/html/website;
index /index/index.html;
}
location /creditapi {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://172.16.3.9:7373/creditapi;
}
location /websiteapi {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://172.16.3.9:7171/websiteapi;
}
#配置Nginx动静分离,定义Html从目录读取。
location ~ .*\.(html)$ {
root /usr/local/nginx/html/website/pages;
#expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 1d;
}
location ^~ /assets/ {
root /usr/local/nginx/html/website;
#expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 1d;
}
location ^~ /common/ {
root /usr/local/nginx/html/website;
#expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 1d;
}
location ~ .*\.(css|js)$ {
root /usr/local/nginx/html/website/pages;
#expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 1d;
}
}
【wechat】
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /www/ssl/wx.domin.gov.cn.pem; #证书文件
ssl_certificate_key /www/ssl/wx.domin.gov.cn.key;
server_name wx.domin.gov.cn;
# listen 80;
charset utf-8;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
location / {
root /usr/local/nginx/html/wechat;
index index.html;
}
location /api {
proxy_pass http://172.16.3.9:7272/wxapi;
}
}