• nginx基本配置-基于nuc980开发板的笔记


    一、介绍

        前面的文章,介绍了如何移植nginx到开发板,打开的网页面是默认的网页。下面介绍如何输入网址变为指定的网页。

    二、配置

    ①将编写的网页,放到html文件夹下,如下图:

    0cdf27f4dca5c49efa5bb51007b93533.png

    ②打开nginx配置文件

    e0681c499a74eb4c7053c971c1f4424d.png

    ③进行nginx相关配置;

    原配置文件:

    1. #user nobody;
    2. worker_processes 1;
    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. events {
    8. worker_connections 1024;
    9. }
    10. http {
    11. include mime.types;
    12. default_type application/octet-stream;
    13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    14. # '$status $body_bytes_sent "$http_referer" '
    15. # '"$http_user_agent" "$http_x_forwarded_for"';
    16. #access_log logs/access.log main;
    17. sendfile on;
    18. #tcp_nopush on;
    19. #keepalive_timeout 0;
    20. keepalive_timeout 65;
    21. #gzip on;
    22. server {
    23. listen 80;
    24. server_name localhost;
    25. #charset koi8-r;
    26. #access_log logs/host.access.log main;
    27. location / {
    28. root html;
    29. index index.html index.htm;
    30. }
    31. #error_page 404 /404.html;
    32. # redirect server error pages to the static page /50x.html
    33. #
    34. error_page 500 502 503 504 /50x.html;
    35. location = /50x.html {
    36. root html;
    37. }
    38. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    39. #
    40. #location ~ \.php$ {
    41. # proxy_pass http://127.0.0.1;
    42. #}
    43. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    44. #
    45. #location ~ \.php$ {
    46. # root html;
    47. # fastcgi_pass 127.0.0.1:9000;
    48. # fastcgi_index index.php;
    49. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    50. # include fastcgi_params;
    51. #}
    52. # deny access to .htaccess files, if Apache's document root
    53. # concurs with nginx's one
    54. #
    55. #location ~ /\.ht {
    56. # deny all;
    57. #}
    58. }
    59. # another virtual host using mix of IP-, name-, and port-based configuration
    60. #
    61. #server {
    62. # listen 8000;
    63. # listen somename:8080;
    64. # server_name somename alias another.alias;
    65. # location / {
    66. # root html;
    67. # index index.html index.htm;
    68. # }
    69. #}
    70. # HTTPS server
    71. #
    72. #server {
    73. # listen 443 ssl;
    74. # server_name localhost;
    75. # ssl_certificate cert.pem;
    76. # ssl_certificate_key cert.key;
    77. # ssl_session_cache shared:SSL:1m;
    78. # ssl_session_timeout 5m;
    79. # ssl_ciphers HIGH:!aNULL:!MD5;
    80. # ssl_prefer_server_ciphers on;
    81. # location / {
    82. # root html;
    83. # index index.html index.htm;
    84. # }
    85. #}
    86. }

    修改后的配置文件如下:

    1. #user nobody;
    2. worker_processes 1;
    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. events {
    8. worker_connections 1024;
    9. }
    10. http {
    11. include mime.types;
    12. default_type application/octet-stream;
    13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    14. # '$status $body_bytes_sent "$http_referer" '
    15. # '"$http_user_agent" "$http_x_forwarded_for"';
    16. #access_log logs/access.log main;
    17. sendfile on;
    18. #tcp_nopush on;
    19. #keepalive_timeout 0;
    20. keepalive_timeout 65;
    21. #gzip on;
    22. server {
    23.         listen       80;# 前端端口
    24. server_name localhost;
    25. #charset koi8-r;
    26. #access_log logs/host.access.log main;
    27. # 增加部分-start
    28. gzip on;# 压缩使能,加快启动速度
    29. gzip_min_length 1k;
    30. gzip_comp_level 9;
    31. gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    32. gzip_vary on;
    33. gzip_disable "MSIE [1-6]\.";
    34. client_max_body_size 50m;
    35. # 增加部分-end
    36. location / {
    37. root html;
    38. index index.html index.htm;
    39. }
    40. # 增加部分-start
    41. location /api {
    42.     proxy_pass http://127.0.0.1:8000; # 后端端口
    43. proxy_read_timeout 3600;
    44. proxy_set_header x-forwarded-for $remote_addr;
    45. }
    46.   # 增加部分-end
    47. #error_page 404 /404.html;
    48. # redirect server error pages to the static page /50x.html
    49. #
    50. error_page 500 502 503 504 /50x.html;
    51. location = /50x.html {
    52. root html;
    53. }
    54. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    55. #
    56. #location ~ \.php$ {
    57. # proxy_pass http://127.0.0.1;
    58. #}
    59. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    60. #
    61. #location ~ \.php$ {
    62. # root html;
    63. # fastcgi_pass 127.0.0.1:9000;
    64. # fastcgi_index index.php;
    65. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    66. # include fastcgi_params;
    67. #}
    68. # deny access to .htaccess files, if Apache's document root
    69. # concurs with nginx's one
    70. #
    71. #location ~ /\.ht {
    72. # deny all;
    73. #}
    74. }
    75. # another virtual host using mix of IP-, name-, and port-based configuration
    76. #
    77. #server {
    78. # listen 8000;
    79. # listen somename:8080;
    80. # server_name somename alias another.alias;
    81. # location / {
    82. # root html;
    83. # index index.html index.htm;
    84. # }
    85. #}
    86. # HTTPS server
    87. #
    88. #server {
    89. # listen 443 ssl;
    90. # server_name localhost;
    91. # ssl_certificate cert.pem;
    92. # ssl_certificate_key cert.key;
    93. # ssl_session_cache shared:SSL:1m;
    94. # ssl_session_timeout 5m;
    95. # ssl_ciphers HIGH:!aNULL:!MD5;
    96. # ssl_prefer_server_ciphers on;
    97. # location / {
    98. # root html;
    99. # index index.html index.htm;
    100. # }
    101. #}
    102. }

    至此,启动nginx即可。在浏览器输入地址,即可打开指定的网页,并可以进行前后端通信。

    欢迎关注公众号:嵌入式学习与实践

  • 相关阅读:
    Matlab:Matlab编程语言学习之常用运算操作符、常用函数(逻辑函数、运算函数、交互函数等)简介、使用方法之详细攻略
    MySQL存储引擎
    python趣味编程-5分钟实现一个蛇梯游戏(含源码、步骤讲解)
    opensbi firmware源码分析(3)
    【自然语言处理】基于python的问答系统实现
    C语言第十二课(中):操作符详解【单目、关系、逻辑、条件操作符】
    字节测开耗时三碗蛋炒饭写下的web自动化测试全流程
    Docker 部署 MySQL容器 & 使用脚本部署
    Linux su sudo命令
    中国行政区域带坐标经纬度sql文件及地点获取经纬度方法
  • 原文地址:https://blog.csdn.net/weixin_46158019/article/details/134432563