博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx笔记
阅读量:6802 次
发布时间:2019-06-26

本文共 5579 字,大约阅读时间需要 18 分钟。

hot3.png

常用命令

./nginx         #run nginx   windows下用start nginxnginx -s stop	#fast shutdownnginx -s quit	#graceful shutdown#changing configuration, starting new worker processes with a new#configuration, graceful shutdown of old worker processesnginx -s reloadnginx -s reopen	#re-opening log files

nginx.conf配置,搞定非智力的技术

#user  nobody;   配置允许运行nginx服务的用户和用户组  eg: user nobogy nobodyworker_processes  3;    # 配置允许Nginx进程生成的worker process数#error_log  logs/error.log;         # 配置nginx服务运行中生成的日志的存放路径#error_log  logs/error.log  notice;   # 配置日志存放路径,满足该日志级别notice的日志会记录到该日志文件#error_log  logs/error.log  info;    # 日志级别  info#pid        logs/nginx.pid;     # nginx进程文件路径,默认events {    worker_connections  1024;   # 配置最大连接数}http {    include       mime.types;                   # 定义MIME-Type    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;     # 配置允许使用sendfile方式传输    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    # 配置连接超时时间    #gzip  on;    # 是否开始gzip 压缩,  对于开放大json数据,建议开启压缩    # 配置虚拟主机  1    server {        # 配置监听的      域名和端口        listen       8081;        server_name  localhost;    #  配置成服务器的域名        # 定义字符集  utf-8        charset utf-8;        #access_log  logs/host.access.log  main;        # 访问日志  路径,格式,  可以用绝对路径        access_log  myweb/server1/log/access.log  main;                                # 配置访问路径  http://myServer1:8081/server1/location1的根目录,首页        location /server1/location1 {            root   myweb;   # 不是/开头的为相对路径            index  index.html index.htm;        }        location /server1/location2 {            root   myweb;   # 不是/开头的为相对路径            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;        # 访问路径  http://myServer1:8081/50x.html,  到  root目录去找文件        location = /50x.html {            root   myweb;        }        location = /404.html {            root   myweb;        }        # 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;        #}    }    # 配置虚拟主机  2    server {               listen       8082;        server_name  127.0.0.1;        charset utf-8;        #access_log  logs/host.access.log  main;        # 访问日志  路径,格式,  可以用绝对路径        access_log  myweb/server2/log/access.log  main;                                # 配置访问路径  http://myServer1:8081/server1/location1的根目录,首页        location /server2/location1 {            root   myweb;   # 不是/开头的为相对路径            index  index.html index.htm;        }        location /svr2/loc2 {            alias myweb/server2/location2/;  #对location的URI进行更改            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;        # 访问路径  http://myServer1:8081/50x.html,  到  root目录去找文件        location = /50x.html {            root   myweb;        }        location = /404.html {            root   myweb;        }        # 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       443 ssl;    #    server_name  localhost;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_cache    shared:SSL:1m;    #    ssl_session_timeout  5m;    #    ssl_ciphers  HIGH:!aNULL:!MD5;    #    ssl_prefer_server_ciphers  on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}

目录结构如下:这里用的是相对目录,在nginx的安装目录下新建一个myweb目录。

174800_NAtP_3071470.png

访问测试

175102_9gxv_3071470.png

175043_gGbp_3071470.png

175118_SsX6_3071470.png

175132_L9KT_3071470.png

175145_eqSI_3071470.png

175409_MyT1_3071470.png

 

转载于:https://my.oschina.net/hutaishi/blog/1559316

你可能感兴趣的文章
TNS-01190故障的处理
查看>>
C++ Exercises(十)
查看>>
《kali linux 渗透测试初级教程》免费下载
查看>>
[Oracle]PDB Clone 方法
查看>>
JavaScript词法作用域与调用对象
查看>>
当谈论设备指纹时,我们到底在说什么?(转)
查看>>
Python天天美味(10) - 除法小技巧
查看>>
webrtc进阶-信令篇-之三:信令、stun、turn、ice
查看>>
.NET调试实例-信息和安装说明 (原创翻译)
查看>>
ThinkPHP 数据库操作之数据表模型和基础模型 ( Model
查看>>
Listener and sqlnet trace
查看>>
Unity3D对安卓盒子的支持
查看>>
redis源码笔记 - redis-cli.c
查看>>
QTabWiget Change Color 改变颜色
查看>>
模板方法在Spring事务中的应用
查看>>
Ext.LoadMask遮罩的效果几种实现方式
查看>>
理解SQL SERVER中非聚集索引的覆盖,连接,交叉和过滤
查看>>
各个JAVA场景下的内存图
查看>>
用GMF生成简化的数据库设计器
查看>>
【干货】程序员常访问的国外技术交流网站汇总
查看>>