前端nginx部署方案(参考)

安装nginx

Ubuntu

sudo apt-get install nginx
安装好的文件位置:
/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志

在/etc/nginx/nginx.conf文件中新增一行,如图:

在conf下面创建一个vhost目录
进入vhost目录
上传www.your.com_web_80.conf,其中,把your替换成你自己的名字


替换图中内容,其中,/data/www/ 是代码路径,将图中名称替换为你自己的名称

service nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}命令启动。

systemctl status nginx查看状态

nginx.conf文件

  1. #user www;
  2. worker_processes 3;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. worker_rlimit_nofile 65535;
  8. events {
  9. use epoll;
  10. worker_connections 65535;
  11. }
  12. http {
  13. include mime.types;
  14. default_type application/octet-stream;
  15. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  16. '$status $body_bytes_sent "$http_referer" '
  17. '"$http_user_agent" "$http_x_forwarded_for"';
  18. access_log logs/access.log main;
  19. sendfile on;
  20. tcp_nopush on;
  21. #keepalive_timeout 0;
  22. #keepalive_timeout 65;
  23. tcp_nodelay on;
  24. server_tokens off;
  25. client_max_body_size 30m;
  26. keepalive_timeout 60;
  27. fastcgi_connect_timeout 300;
  28. fastcgi_send_timeout 300;
  29. fastcgi_read_timeout 300;
  30. fastcgi_buffer_size 64k;
  31. fastcgi_buffers 4 64k;
  32. fastcgi_busy_buffers_size 128k;
  33. fastcgi_temp_file_write_size 128k;
  34. fastcgi_intercept_errors on;
  35. gzip on;
  36. #gzip_static on;
  37. gzip_proxied any;
  38. gzip_comp_level 5;
  39. gzip_min_length 1024;
  40. gzip_vary on;
  41. gzip_buffers 4 8k;
  42. gzip_http_version 1.1;
  43. gzip_types text/plain text/css application/x-javascript. text/xml application/xml application/xml+rss text/javascript;
  44. include vhost/*.conf;
  45. }

www.your.com_web_80.conf 文件

  1. server
  2. {
  3. listen 80;
  4. server_name www.your.com;
  5. index index.html index.htm index.php index.jsp;
  6. access_log /data/program/nginx/logs/$server_name.access.log;
  7. location / {
  8. root /data/www/zl_website/;
  9. try_files $uri /index.html
  10. index index.html index.htm;
  11. }
  12. }
  1. 验证nginx启动成功,访问nginx所在的ip即可,会出现nginx首页
  1. nginx首页访问失败 404
  2. 1.检查配置文件,是否全部按照文档部署
  3. 2.检查nginx权限,参考
  4. https://www.cnblogs.com/xiaohuiduan/p/9867656.html
  1. [rihide]获客文章nginx配置方案
    1. server {
    2. listen 80;
    3. #listen [::]:80;
    4. server_name weixin.yiliit.com
    5. index index.html index.htm;
    6. #文章映射路径
    7. root /usr/share/nginx/html/dynamic;
    8. error_page 404 /404.html;
    9. location =/404.html {
    10. root /usr/share/nginx/html;
    11. }
    12. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
    13. expires 30d;
    14. }
    15. location ~ .*\.(js|css)?$ {
    16. expires 12h;
    17. }
    18. location ~ /.well-known {
    19. allow all;
    20. }
    21. location ~ /\. {
    22. deny all;
    23. }
    24. #后端服务api,如果配置了跨域问题可以直接使用api.youdomain.com访问
    25. location /wechatApi {
    26. proxy_pass https://api.yiliit.com/wechatApi;
    27. proxy_redirect default ;
    28. proxy_set_header Host $host;
    29. proxy_set_header X-Real-IP $remote_addr;
    30. proxy_set_header REMOTE-HOST $remote_addr;
    31. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    32. }
    33. location /crmApi {
    34. proxy_pass https://api.yiliit.com/crmApi;
    35. proxy_redirect default ;
    36. proxy_set_header Host $host;
    37. proxy_set_header X-Real-IP $remote_addr;
    38. proxy_set_header REMOTE-HOST $remote_addr;
    39. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    40. }
    41. server_tokens off;
    42. sendfile off;
    43. access_log /var/log/crm.com_access.log;
    44. }

    微信校验文件访问nginx方案: 将微信校验文件放在/home/resource/下,nginx配置如下:

    1. server {
    2. listen 80;
    3. server_name wx.yiliit.com;
    4. root /home/resource/;
    5. index index.html;
    6. location / {
    7. }
    8. error_page 404 /404.html;
    9. location = /40x.html {
    10. }
    11. error_page 500 502 503 504 /50x.html;
    12. location = /50x.html {
    13. }
    14. }

    [/rihide]

发表回复