安装

  1. wget下载源码
  2. 解压:tar -xzf nginx.tar.gz
  3. 执行配置文件:./configure
  4. make
  5. make install

    常用命令

  1. nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
  2. nginx -s quit 平稳关闭Nginx,保存相关信息,有安排的结束web服务。
  3. nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载。
  4. nginx -s reopen 重新打开日志文件。
  5. nginx -c filename Nginx 指定一个配置文件,来代替缺省的。
  6. nginx -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
  7. nginx -v 显示 nginx 的版本。
  8. nginx -V 显示 nginx 的版本,编译器版本和配置参数。

配置文件路径

/etc/nginx

参考地址

https://zhuanlan.zhihu.com/p/58962596

安装相关:https://github.com/dunwu/nginx-tutorial/blob/master/install-nginx.md

asp.net core部署及https配置

  1. # For more information on configuration, see:
  2. # * Official English Documentation: http://nginx.org/en/docs/
  3. # * Official Russian Documentation: http://nginx.org/ru/docs/
  4. user nginx;
  5. worker_processes auto;
  6. error_log /var/log/nginx/error.log;
  7. pid /run/nginx.pid;
  8. # Load dynamic modules. See /usr/share/nginx/README.dynamic.
  9. include /usr/share/nginx/modules/*.conf;
  10. events {
  11. worker_connections 1024;
  12. }
  13. http {
  14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. '$status $body_bytes_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';
  17. access_log /var/log/nginx/access.log main;
  18. sendfile on;
  19. tcp_nopush on;
  20. tcp_nodelay on;
  21. keepalive_timeout 65;
  22. types_hash_max_size 2048;
  23. include /etc/nginx/mime.types;
  24. default_type application/octet-stream;
  25. # Load modular configuration files from the /etc/nginx/conf.d directory.
  26. # See http://nginx.org/en/docs/ngx_core_module.html#include
  27. # for more information.
  28. include /etc/nginx/conf.d/*.conf;
  29. server {
  30. listen 80;
  31. # Load configuration files for the default server block.
  32. include /etc/nginx/default.d/*.conf;
  33. location / {
  34. proxy_pass http://localhost:5000;
  35. proxy_http_version 1.1;
  36. proxy_set_header Upgrade $http_upgrade;
  37. proxy_set_header Connection keep-alive;
  38. proxy_set_header Host $host;
  39. proxy_cache_bypass $http_upgrade;
  40. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  41. proxy_set_header X-Forwarded-Proto $scheme;
  42. }
  43. error_page 404 /404.html;
  44. location = /40x.html {
  45. }
  46. error_page 500 502 503 504 /50x.html;
  47. location = /50x.html {
  48. }
  49. }
  50. # Settings for a TLS enabled server.
  51. #
  52. server {
  53. listen 443;
  54. server_name localhost;
  55. ssl on;
  56. #root /usr/share/nginx/html;
  57. ssl_certificate cert/214817408410547.pem;
  58. ssl_certificate_key cert/214817408410547.key;
  59. ssl_session_timeout 5m;
  60. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  61. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  62. ssl_prefer_server_ciphers on;
  63. # Load configuration files for the default server block.
  64. #include /etc/nginx/default.d/*.conf;
  65. location / {
  66. proxy_pass http://localhost:5000;
  67. proxy_http_version 1.1;
  68. proxy_set_header Upgrade $http_upgrade;
  69. proxy_set_header Connection keep-alive;
  70. proxy_set_header Host $host;
  71. proxy_cache_bypass $http_upgrade;
  72. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  73. proxy_set_header X-Forwarded-Proto $scheme;
  74. }
  75. # error_page 404 /404.html;
  76. # location = /40x.html {
  77. # }
  78. # error_page 500 502 503 504 /50x.html;
  79. # location = /50x.html {
  80. # }
  81. }
  82. }