1. 添加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)

    1. 安装Nginx

    sudo yum install -y nginx

    安装后的默认目录:
    配置文件: /etc/nginx/nginx.conf
    自定义的配置文件夹: /etc/nginx/conf.d
    项目文件: /usr/share/nginx/html/

    1. default
    2. server {
    3. # 当http协议被请求时,统一转发到https协议商
    4. listen 80;
    5. listen [::]:80; #IPV6协议
    6. server_name domain.com;
    7. rewrite ^(.*)$ https://$host$1 permanent;
    8. }
    9. image
    10. server {
    11. listen 443 ssl;
    12. listen [::]:443 ssl;
    13. ssl_certificate /www/ssl/image.domin.gov.cn.pem; #证书文件
    14. ssl_certificate_key /www/ssl/image.domin.gov.cn.key;
    15. server_name image.domin.gov.cn;
    16. #listen 80;
    17. location / {
    18. proxy_pass http://172.16.3.5/res/;
    19. }
    20. #plugin service
    21. location /rabbitmq {
    22. proxy_pass http://172.16.3.5:15672/;
    23. }
    24. location /kibana {
    25. proxy_pass http://172.16.3.5:5601/app/kibana;
    26. }
    27. }
    28. web
    29. server {
    30. listen 443 ssl;
    31. listen [::]:443 ssl;
    32. ssl_certificate /www/ssl/creditplatform.domin.gov.cn.pem; #证书文件
    33. ssl_certificate_key /www/ssl/creditplatform.domin.gov.cn.key;
    34. server_name creditplatform.domin.gov.cn;
    35. # listen 80;
    36. location / {
    37. proxy_pass http://172.16.3.7:7070;
    38. }
    39. }
    40. website
    41. server{
    42. listen 443 ssl;
    43. listen [::]:443 ssl;
    44. ssl_certificate /www/ssl/www.domin.gov.cn.pem; #证书文件
    45. ssl_certificate_key /www/ssl/www.domin.gov.cn.key;
    46. server_name www.domin.gov.cn;
    47. #listen 80;
    48. charset utf-8;
    49. location / {
    50. root /usr/local/nginx/html/website;
    51. index /index/index.html;
    52. }
    53. location /creditapi {
    54. proxy_set_header X-Real-IP $remote_addr;
    55. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    56. proxy_set_header Host $http_host;
    57. proxy_set_header X-NginX-Proxy true;
    58. proxy_pass http://172.16.3.9:7373/creditapi;
    59. }
    60. location /websiteapi {
    61. proxy_set_header X-Real-IP $remote_addr;
    62. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    63. proxy_set_header Host $http_host;
    64. proxy_set_header X-NginX-Proxy true;
    65. proxy_pass http://172.16.3.9:7171/websiteapi;
    66. }
    67. #配置Nginx动静分离,定义Html从目录读取。
    68. location ~ .*\.(html)$ {
    69. root /usr/local/nginx/html/website/pages;
    70. #expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
    71. expires 1d;
    72. }
    73. location ^~ /assets/ {
    74. root /usr/local/nginx/html/website;
    75. #expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
    76. expires 1d;
    77. }
    78. location ^~ /common/ {
    79. root /usr/local/nginx/html/website;
    80. #expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
    81. expires 1d;
    82. }
    83. location ~ .*\.(css|js)$ {
    84. root /usr/local/nginx/html/website/pages;
    85. #expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
    86. expires 1d;
    87. }
    88. }
    89. wechat
    90. server {
    91. listen 443 ssl;
    92. listen [::]:443 ssl;
    93. ssl_certificate /www/ssl/wx.domin.gov.cn.pem; #证书文件
    94. ssl_certificate_key /www/ssl/wx.domin.gov.cn.key;
    95. server_name wx.domin.gov.cn;
    96. # listen 80;
    97. charset utf-8;
    98. proxy_set_header X-Real-IP $remote_addr;
    99. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    100. proxy_set_header Host $http_host;
    101. proxy_set_header X-NginX-Proxy true;
    102. location / {
    103. root /usr/local/nginx/html/wechat;
    104. index index.html;
    105. }
    106. location /api {
    107. proxy_pass http://172.16.3.9:7272/wxapi;
    108. }
    109. }

    离线安装参考