飞道的博客

Linux CentOS + Nginx 搭建网站

490人阅读  评论(0)

Nginx (engine x) 是一个高性能的HTTP反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。

Nginx是一款轻量级Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,使用nginx网站用户有:百度、京东新浪网易腾讯淘宝等。

 

在centOs上,是可以直接用yum命令来安装Nginx。


  
  1. // 用yum来安装nginx
  2. yum install nginx -y
  3. // 安装完毕,启动nginx
  4. nginx

安装启动后,在chrome中输入对应的服务器ip地址,就可以看到nginx默认页面

在/etc/nginx/nginx.conf配置文件中配置你自己的项目目录,并让nginx正确访问。

/etc/nginx/nginx.conf文件修改配置(最主要的是server { }内的内容,本人配置了四个网页地址:访问为http://127.0.0.1、http://127.0.0.1/html、http://127.0.0.1/fangjiaqian、http://127.0.0.1/yoyo):


  
  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/doc/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 default_server;
  31. listen [::]:80 default_server;
  32. server_name _;
  33. root /usr/share/nginx/html;
  34. # Load configuration files for the default server block.
  35. include /etc/nginx/default.d/*.conf;
  36. location / {
  37. root /var/www;
  38. index index.html;
  39. }
  40. location /html {
  41. root /var/www;
  42. index index.html;
  43. }
  44. location /fangjiaqian {
  45. root /var/www;
  46. index fangjiaqian.html;
  47. }
  48. location /yoyo {
  49. root /var/www;
  50. index index.html;
  51. }
  52. error_page 404 /404.html;
  53. location = /40x.html {
  54. }
  55. error_page 500 502 503 504 /50x.html;
  56. location = /50x.html {
  57. }
  58. }
  59. # Settings for a TLS enabled server.
  60. #
  61. # server {
  62. # listen 443 ssl http2 default_server;
  63. # listen [::]:443 ssl http2 default_server;
  64. # server_name _;
  65. # root /usr/share/nginx/html;
  66. #
  67. # ssl_certificate "/etc/pki/nginx/server.crt";
  68. # ssl_certificate_key "/etc/pki/nginx/private/server.key";
  69. # ssl_session_cache shared:SSL:1m;
  70. # ssl_session_timeout 10m;
  71. # ssl_ciphers HIGH:!aNULL:!MD5;
  72. # ssl_prefer_server_ciphers on;
  73. #
  74. # # Load configuration files for the default server block.
  75. # include /etc/nginx/default.d/*.conf;
  76. #
  77. # location / {
  78. # }
  79. #
  80. # error_page 404 /404.html;
  81. # location = /40x.html {
  82. # }
  83. #
  84. # error_page 500 502 503 504 /50x.html;
  85. # location = /50x.html {
  86. # }
  87. # }
  88. }

配置完成后,需要重启nginx


  
  1. // 重启nginx
  2. nginx -s reload


转载:https://blog.csdn.net/wukai0909/article/details/105208507
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场