python html5 bootstrap 视频教程

德云社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 6023|回复: 0

在 Ubuntu Server 14.04 下安装 Nginx 1.4.6

[复制链接]

172

主题

258

帖子

1114

积分

版主

Rank: 7Rank: 7Rank: 7

金钱
663
金币
7
威望
0
贡献
0
发表于 2014-12-26 00:01:33 | 显示全部楼层 |阅读模式
AI人工智能 语音助理 人工翻译 教程
在 Ubuntu Server 14.04 下安装 Nginx 1.4.6

       Nginx ("engine x") 是高性能 HTTP、反向代理服务器,也是 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一公开版本 0.1.0 发布于 2004 年 10 月 4 日。源代码以BSD-like 许可证的形式发布,因其稳定性、丰富功能集、示例配置文件、低系统资源消耗而闻名。2011 年 6 月 1 日,nginx 1.0.4 发布。

      其特点是:占有内存少、并发能力强。事实上,nginx 的并发能力确实在同类型网页服务器中表现较好,中国大陆使用 nginx 网站用户有:新浪、网易、腾讯等。

1、安装 Nginx
  1. apt-get install nginx
复制代码

2、在 FireFox 或 IE 浏览器中键入 http://localhost/ 或 http://127.0.0.1/ (或服务器 IP 地址);若出现 “Welcome to nginx!” 信息,说明安装成功:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

3、编辑 Nginx 配置文件
  1. vi /etc/nginx/sites-available/default
复制代码
     

修改前的配置文件内容:

  1. # You may add here your
  2. # server {
  3. #        ...
  4. # }
  5. # statements for each of your virtual hosts to this file

  6. ##
  7. # You should look at the following URL's in order to grasp a solid understanding
  8. # of Nginx configuration files in order to fully unleash the power of Nginx.
  9. # http://wiki.nginx.org/Pitfalls
  10. # http://wiki.nginx.org/QuickStart
  11. # http://wiki.nginx.org/Configuration
  12. #
  13. # Generally, you will want to move this file somewhere, and start with a clean
  14. # file but keep this around for reference. Or just disable in sites-enabled.
  15. #
  16. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  17. ##

  18. server {    #设定虚拟主机,默认为监听 80 端口,改成其他端口会出现问题   
  19.         listen 80 default_server;
  20.         listen [::]:80 default_server ipv6only=on;

  21.         root /usr/share/nginx/html;      #定义服务器默认网站根目录位置
  22.         index index.html index.htm;     #定义首页索引文件名称

  23.         # Make site accessible from http://localhost/
  24.         server_name localhost;      #域名可以有多个,使用空格分隔

  25.         location / {     #默认请求
  26.                 # First attempt to serve request as file, then
  27.                 # as directory, then fall back to displaying a 404.
  28.                 try_files $uri $uri/ =404;
  29.                 # Uncomment to enable naxsi on this location
  30.                 # include /etc/nginx/naxsi.rules
  31.         }

  32.         # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
  33.         #location /RequestDenied {
  34.         #        proxy_pass http://127.0.0.1:8080;   
  35.         #}

  36.         #error_page 404 /404.html;

  37.         # redirect server error pages to the static page /50x.html
  38.         #
  39.         #error_page 500 502 503 504 /50x.html;
  40.         #location = /50x.html {      #定义错误提示页面
  41.         #        root /usr/share/nginx/html;
  42.         #}

  43.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  44.         #
  45.         #location ~ \.php$ {     #PHP 脚本请求全部转发到 FastCGI 处理. 使用 FastCGI 默认配置
  46.         #        fastcgi_split_path_info ^(.+\.php)(/.+)$;
  47.         #        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  48.         #
  49.         #        # With php5-cgi alone:
  50.         #        fastcgi_pass 127.0.0.1:9000;
  51.         #        # With php5-fpm:
  52.         #        fastcgi_pass unix:/var/run/php5-fpm.sock;
  53.         #        fastcgi_index index.php;
  54.         #        include fastcgi_params;
  55.         #}

  56.         # deny access to .htaccess files, if Apache's document root
  57.         # concurs with nginx's one
  58.         #
  59.         #location ~ /\.ht {    #禁止访问 .htaccess 文件
  60.         #        deny all;
  61.         #}
  62. }


  63. # another virtual host using mix of IP-, name-, and port-based configuration
  64. #
  65. #server {
  66. #        listen 8000;
  67. #        listen somename:8080;
  68. #        server_name somename alias another.alias;
  69. #        root html;
  70. #        index index.html index.htm;
  71. #
  72. #        location / {
  73. #                try_files $uri $uri/ =404;
  74. #        }
  75. #}


  76. # HTTPS server
  77. #
  78. #server {
  79. #        listen 443;
  80. #        server_name localhost;
  81. #
  82. #        root html;
  83. #        index index.html index.htm;
  84. #
  85. #        ssl on;
  86. #        ssl_certificate cert.pem;
  87. #        ssl_certificate_key cert.key;
  88. #
  89. #        ssl_session_timeout 5m;
  90. #
  91. #        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  92. #        ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
  93. #        ssl_prefer_server_ciphers on;
  94. #
  95. #        location / {
  96. #                try_files $uri $uri/ =404;
  97. #        }
  98. #}
复制代码
      

修改后的配置文件内容:

  1. # You may add here your
  2. # server {
  3. #    ...
  4. # }
  5. # statements for each of your virtual hosts to this file

  6. ##
  7. # You should look at the following URL's in order to grasp a solid understanding
  8. # of Nginx configuration files in order to fully unleash the power of Nginx.
  9. # http://wiki.nginx.org/Pitfalls
  10. # http://wiki.nginx.org/QuickStart
  11. # http://wiki.nginx.org/Configuration
  12. #
  13. # Generally, you will want to move this file somewhere, and start with a clean
  14. # file but keep this around for reference. Or just disable in sites-enabled.
  15. #
  16. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  17. ##

  18. server {    #设定虚拟主机,默认为监听 80 端口,改成其他端口会出现问题
  19.     listen 80 default_server;
  20.     listen [::]:80 default_server ipv6only=on;

  21.     root /usr/share/nginx/html;      #定义服务器默认网站根目录位置
  22.     index index.html index.htm;     #定义首页索引文件名称

  23.     # Make site accessible from http://localhost/
  24.     server_name localhost;    #域名可以有多个,使用空格分隔

  25.     location /  {    #默认请求
  26.         # First attempt to serve request as file, then
  27.         # as directory, then fall back to displaying a 404.
  28.         try_files $uri $uri/ =404;
  29.         # Uncomment to enable naxsi on this location
  30.         # include /etc/nginx/naxsi.rules
  31.     }

  32.     #图片缓存时间设置
  33.     location ~.*/\.(jpg|jpeg|png|gif|swf)$
  34.     {
  35.         expires 30d;
  36.     }

  37.     location ~.*/\.(js|css)?$;    #JS 和 CSS 缓存时间设置
  38.     {
  39.         expires 1h;
  40.     }

  41.     # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
  42.     #location /RequestDenied {
  43.     #    proxy_pass http://127.0.0.1:8080;   
  44.     #}

  45.     #error_page 404 /404.html;

  46.     # redirect server error pages to the static page /50x.html
  47.     #
  48.     #error_page 500 502 503 504 /50x.html;
  49.     #location = /50x.html {     # 定义错误提示页面
  50.     #    root /usr/share/nginx/html;
  51.     #}

  52.     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  53.     #      
  54.     #location ~ \.php$ {      #PHP 脚本请求全部转发到 FastCGI 处理. 使用 FastCGI 默认配置
  55.     #    fastcgi_split_path_info ^(.+\.php)(/.+)$;
  56.     #    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  57.     #
  58.     #    # With php5-cgi alone:
  59.     #    fastcgi_pass 127.0.0.1:9000;
  60.     #    # With php5-fpm:
  61.     #    fastcgi_pass unix:/var/run/php5-fpm.sock;
  62.     #    fastcgi_index index.php;
  63.     #    include fastcgi_params;
  64.     #}

  65.     # deny access to .htaccess files, if Apache's document root
  66.     # concurs with nginx's one
  67.     #
  68.     #location ~ /\.ht  {     #禁止访问 .htaccess 文件
  69.     #    deny all;
  70.     #}
  71. }


  72. # another virtual host using mix of IP-, name-, and port-based configuration
  73. #
  74. #server {
  75. #    listen 8000;
  76. #    listen somename:8080;
  77. #    server_name somename alias another.alias;
  78. #    root html;
  79. #    index index.html index.htm;
  80. #
  81. #    location / {
  82. #        try_files $uri $uri/ =404;
  83. #    }
  84. #}


  85. # HTTPS server
  86. #
  87. #server {
  88. #    listen 443;
  89. #    server_name localhost;
  90. #
  91. #    root html;
  92. #    index index.html index.htm;
  93. #
  94. #    ssl on;
  95. #    ssl_certificate cert.pem;
  96. #    ssl_certificate_key cert.key;
  97. #
  98. #    ssl_session_timeout 5m;
  99. #
  100. #    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  101. #    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
  102. #    ssl_prefer_server_ciphers on;
  103. #
  104. #    location / {
  105. #        try_files $uri $uri/ =404;
  106. #    }
  107. #}
复制代码

4、
重载测试 Nginx 配置文件
  1. root:# /usr/sbin/nginx -s reload (或 service nginx reload)
  2. root:# /usr/sbin/nginx -t
  3. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  4. nginx: configuration file /etc/nginx/nginx.conf test is successful
  5. root:#
复制代码

5、重启 Nginx
  1. root:# /etc/init.d/nginx restart
  2. * Restarting nginx nginx                                                                                                [ OK ]
  3. root:#
复制代码

6、发布您的网站
      将您网站带有 index.html 文件的目录下的所有文件、目录上传到 /var/www 目录下

7、浏览网站
       在 FireFox 或 IE 浏览器中键入 http://localhost/ 或 http://127.0.0.1/  (或服务器 IP 地址),浏览您的网站;

版权声明:
本文为独家原创稿件,版权归 德云社区,未经许可不得转载;否则,将追究其法律责任。

AI人工智能 语音助理 人工翻译 教程
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|Sitemap|小黑屋|德云社区 |网站地图  

GMT+8, 2024-4-19 19:20 , Processed in 0.052053 second(s), 27 queries .

工业和信息化部: 粤ICP备14079481号-2

技术支持 乐数软件     版权所有 © 2014-2021 德云社区    

快速回复 返回顶部 返回列表