首先说明一下版本,我下载的是 nginx/1.14.0 (Ubuntu)
    我们都知道 —— 当我们将nginx下载成功后,nginx就默认启动了应用,默认为80端口 —— 为什么呢?我们从nginx的默认配置中一探究竟。

    注意看我的注释# 开头的都是注释其中**中文的# 开头的是我写的注释**,其他的为nginx默认配置的注释。

    当你只是当 _静态web服务器 _这种最基础的使用的话,把我中文标注的内容看懂了就够用**~以后我也会写更多文章分享“更深入”的配置理解(包括性能优化)。

    nginx.conf 文件

    1. # 指定运行用户,可以为root
    2. user www-data;
    3. # 指定子进程数
    4. worker_processes auto;
    5. # 指定运行时的pid的存储位置
    6. pid /run/nginx.pid;
    7. # 指定接受 /etc/nginx/modules-enabled/ 该路径下的所有.conf结尾的配置
    8. # 里面的文件都默认为空
    9. include /etc/nginx/modules-enabled/*.conf;
    10. # 工作模式设置
    11. events {
    12. # 指定最大并发数
    13. worker_connections 768;
    14. # multi_accept on;
    15. }
    16. # http配置设置
    17. http {
    18. ##
    19. # 基础设置
    20. # Basic Settings
    21. ##
    22. sendfile on;
    23. tcp_nopush on;
    24. tcp_nodelay on;
    25. # 指定客户端连接超时时长
    26. keepalive_timeout 65;
    27. types_hash_max_size 2048;
    28. # server_tokens off;
    29. # server_names_hash_bucket_size 64;
    30. # server_name_in_redirect off;
    31. # 指定/etc/nginx/mime.types文件设定mime类型
    32. include /etc/nginx/mime.types;
    33. # 指定默认处理的文件类型为二进制文件
    34. default_type application/octet-stream;
    35. ##
    36. # SSL证书设置
    37. # SSL Settings
    38. ##
    39. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    40. ssl_prefer_server_ciphers on;
    41. ##
    42. # 日志设置
    43. # Logging Settings
    44. ##
    45. # 连接成功的日志打印地址
    46. access_log /var/log/nginx/access.log;
    47. # 连接失败的日志打印地址
    48. error_log /var/log/nginx/error.log;
    49. ##
    50. # Gzip压缩设置
    51. # Gzip Settings
    52. ##
    53. gzip on;
    54. # gzip_vary on;
    55. # gzip_proxied any;
    56. # gzip_comp_level 6;
    57. # gzip_buffers 16 8k;
    58. # gzip_http_version 1.1;
    59. # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    60. ##
    61. # 虚拟主机设置(* 重要)
    62. # Virtual Host Configs
    63. ##
    64. # 指定接受 /etc/nginx/conf.d/ 该路径下的所有.conf结尾的配置,默认里面为空
    65. # 可以将自己的nginx子服务配置统一放到这里管理
    66. include /etc/nginx/conf.d/*.conf;
    67. # 指定接受 /etc/nginx/sites-enabled/下的所以内容
    68. # 路径内有一个default文件,里面是80端口的server设置
    69. # 下面会单独介绍
    70. include /etc/nginx/sites-enabled/*;
    71. }
    72. # 邮件相关的配置
    73. # mail {
    74. # # See sample authentication script at:
    75. # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
    76. #
    77. # # auth_http localhost/auth.php;
    78. # # pop3_capabilities "TOP" "USER";
    79. # # imap_capabilities "IMAP4rev1" "UIDPLUS";
    80. #
    81. # server {
    82. # listen localhost:110;
    83. # protocol pop3;
    84. # proxy on;
    85. # }
    86. #
    87. # server {
    88. # listen localhost:143;
    89. # protocol imap;
    90. # proxy on;
    91. # }
    92. #}

    /etc/nginx/sites-enabled/* 下配置介绍(只有一个文件 default)

    1. ##
    2. # You should look at the following URL's in order to grasp a solid understanding
    3. # of Nginx configuration files in order to fully unleash the power of Nginx.
    4. # https://www.nginx.com/resources/wiki/start/
    5. # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
    6. # https://wiki.debian.org/Nginx/DirectoryStructure
    7. #
    8. # In most cases, administrators will remove this file from sites-enabled/ and
    9. # leave it as reference inside of sites-available where it will continue to be
    10. # updated by the nginx packaging team.
    11. #
    12. # This file will automatically load configuration files provided by other
    13. # applications, such as Drupal or Wordpress. These applications will be made
    14. # available underneath a path with that package name, such as /drupal8.
    15. #
    16. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    17. ##
    18. # 默认的server配置
    19. # Default server configuration
    20. #
    21. server {
    22. # 监听80端口
    23. listen 80 default_server;
    24. listen [::]:80 default_server;
    25. # SSL configuration
    26. #
    27. # SSL configuration
    28. #
    29. # listen 443 ssl default_server;
    30. # listen [::]:443 ssl default_server;
    31. #
    32. # Note: You should disable gzip for SSL traffic.
    33. # See: https://bugs.debian.org/773332
    34. #
    35. # Read up on ssl_ciphers to ensure a secure configuration.
    36. # See: https://bugs.debian.org/765782
    37. #
    38. # Self signed certs generated by the ssl-cert package
    39. # Don't use them in a production server!
    40. #
    41. # include snippets/snakeoil.conf;
    42. # 当前server服务的web文件的根目录
    43. root /home/my-blog/public;
    44. # 如果你使用PHP,那么在下面index内再加入index.php
    45. # Add index.php to the list if you are using PHP
    46. # 访问服务的默认首页文件(顺序依次排开)
    47. index index.html index.htm index.nginx-debian.html;
    48. # 指定server名称,可以为ip/域名,多个配置之间用空格隔开
    49. server_name 59.110.70.85;
    50. # 当前server的路由配置
    51. location / {
    52. # First attempt to serve request as file, then
    53. # as directory, then fall back to displaying a 404.
    54. # 顺序检查文件
    55. # 首次访问是将其当做一个文件查找($uri),
    56. # 如果没有的话再当做文件夹($uri/,有个斜杠代表文件夹),
    57. # 还没有的话返回404
    58. try_files $uri $uri/ =404;
    59. }
    60. # pass PHP scripts to FastCGI server
    61. #
    62. #location ~ \.php$ {
    63. # include snippets/fastcgi-php.conf;
    64. #
    65. # # With php-fpm (or other unix sockets):
    66. # fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    67. # # With php-cgi (or other tcp sockets):
    68. # fastcgi_pass 127.0.0.1:9000;
    69. #}
    70. # deny access to .htaccess files, if Apache's document root
    71. # concurs with nginx's one
    72. #
    73. #location ~ /\.ht {
    74. # deny all;
    75. #}
    76. }
    77. # Virtual Host configuration for example.com
    78. #
    79. # You can move that to a different file under sites-available/ and symlink that
    80. # to sites-enabled/ to enable it.
    81. #
    82. #server {
    83. # listen 80;
    84. # listen [::]:80;
    85. #
    86. # server_name example.com;
    87. #
    88. # root /var/www/example.com;
    89. # index index.html;
    90. #
    91. # location / {
    92. # try_files $uri $uri/ =404;
    93. # }
    94. #}

    参考文章:nginx 简单理解和配置