nginx架设更新服务器

更新服务器采用nginx架设,需要http和https同时访问。

使用ssl模块配置同时支持http和https并存

一 nginx安装

Nginx要支持https,安装的时候需要ssl模块。下载nginx,解压,进入解压目录:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

然后make &&make install

二 生成证书

# 1、首先,进入你想创建证书和私钥的目录,例如:

cd /etc/nginx/

# 2、创建服务器私钥,命令会让你输入一个口令:

openssl genrsa -des3 -out server.key 1024

# 3、创建签名请求的证书(CSR):

openssl req -new -key server.key -out server.csr

# 4、在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:

cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

# 5、最后标记证书使用上述私钥和CSR:

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

三 nginx文件路径配置方式

nginx指定文件路径有两种方式root和alias,root与alias主要区别在于nginx如何解释location后面的uri,这会使两者分别以不同的方式将请求映射到服务器文件上。

最基本的区别

alias 指定的目录是准确的,给location指定一个目录。

root 指定目录的上级目录,并且该上级目录要含有locatoin指定名称的同名目录。

以root方式设置资源路径:

语法: root path;

配置块: http、server、location、if

以alias 方式设置资源路径

语法: alias path;

配置块: location

Example:

location /img/ {

alias /var/www/image/;

}

#若按照上述配置的话,则访问/img/目录里面的文件时,nginx会自动去/var/www/image/目录找文件

location /img/ {

root /var/www/image;

}

#若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件

注意:

1.使用alias时,目录名后面一定要加”/“。

2.使用alias标签的目录块中不能使用rewrite的break。

3.alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。

4.alias只能位于location块中

四 修改配置文件

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

worker_connections  1024;

}

http {

include      mime.types;

default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

#                  '$status $body_bytes_sent "$http_referer" '

#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;

#tcp_nopush    on;

#keepalive_timeout  0;

keepalive_timeout  65;

#gzip  on;

server {

listen      8089;

server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

#location / {

#    root  html;

#    index  index.html index.htm;

#}

location  /trunk/ {

#rewrite ^/eec/(.*)$ /$1 last;

alias /home/mobile_update/Chunks/;

index  index.html index.htm;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page  500 502 503 504  /50x.html;

location = /50x.html {

root  html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#    proxy_pass  http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

#    root          html;

#    fastcgi_pass  127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

#    listen      8000;

#    listen      somename:8080;

#    server_name  somename  alias  another.alias;

#    location / {

#        root  html;

#        index  index.html index.htm;

#    }

#}

# HTTPS server

#

server {

listen      8091 ssl;

server_name  localhost;

ssl                  on;

ssl_certificate    /usr/local/nginx/server.crt;

ssl_certificate_key  /usr/local/nginx/server.key;

ssl_session_cache    shared:SSL:1m;

ssl_session_timeout  5m;

ssl_ciphers  HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers  on;

location  /trunk/{

#rewrite ^/eec/(.*)$ /$1 last;

alias  /home/mobile_update/Chunks/;

#index  index.html index.htm;

}

}

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.ngnix介绍 ngnix www服务软件 俄罗斯人开发 开源 性能很高 本身是一款静态WWW软件 静态小文件...
    逗比punk阅读 6,450评论 1 6
  • I/O模型: 阻塞型、非阻塞型、复用型、信号驱动型、异步 同步/异步:关注消息通知机制 消息通知:同步:等待对方返...
    Net夜风阅读 6,164评论 0 1
  • 1.简介:  Nginx:engine X ,2002年,开源,商业版 http协议:web服务器(类似于ht...
    尛尛大尹阅读 5,905评论 0 3
  • Nginx简介 解决基于进程模型产生的C10K问题,请求时即使无状态连接如web服务都无法达到并发响应量级一万的现...
    魏镇坪阅读 6,345评论 0 9
  • 一、MemCache简介 session MemCache是一个自由、源码开放、高性能、分布式的分布式内存对象缓存...
    李伟铭MIng阅读 9,300评论 2 13

友情链接更多精彩内容