{"action":"opened","issue":{"url":"https://api.github.com/repos/faaaar/faaaar.com/issues/2","repository_url":"https://api.github.com/repos/faaaar/faaaar.com","labels_url":"https://api.github.com/repos/faaaar/faaaar.com/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/faaaar/faaaar.com/issues/2/comments","events_url":"https://api.github.com/repos/faaaar/faaaar.com/issues/2/events","html_url":"https://github.com/faaaar/faaaar.com/issues/2","id":215270011,"number":2,"title":"nginx配置简介","user":{"login":"faaaar","id":12553862,"avatar_url":"https://avatars3.githubusercontent.com/u/12553862?v=3","gravatar_id":"","url":"https://api.github.com/users/faaaar","html_url":"https://github.com/faaaar","followers_url":"https://api.github.com/users/faaaar/followers","following_url":"https://api.github.com/users/faaaar/following{/other_user}","gists_url":"https://api.github.com/users/faaaar/gists{/gist_id}","starred_url":"https://api.github.com/users/faaaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/faaaar/subscriptions","organizations_url":"https://api.github.com/users/faaaar/orgs","repos_url":"https://api.github.com/users/faaaar/repos","events_url":"https://api.github.com/users/faaaar/events{/privacy}","received_events_url":"https://api.github.com/users/faaaar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-03-19T15:05:26Z","updated_at":"2017-03-19T15:05:26Z","closed_at":null,"body":"有小伙伴不太懂这个东西\r\n写一写，自己也复习一次\r\nlocation的相关规则，下次再写😄\r\n<!--more-->\r\n# 安装\r\n此处简单介绍源码安装，查看官方文档[点击这里](http://nginx.org/en/docs/configure.html)\r\n\r\n## 编译参数\r\n列举一些常见的参数\r\n\r\n- `--prefix=PATH` 指定nginx的安装目录。默认 /usr/local/nginx\r\n- `--conf-path=PATH `  设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动，通过命令行中的-c选项。默认为prefix/conf/nginx.conf\r\n- `--user=name` 设置nginx工作进程的用户。\r\n- `--group=name` 设置nginx工作进程的组。\r\n- `--with-pcre` 设置PCRE库的源码路径，如果已通过yum方式安装，使用--with-pcre自动找到库文件。使用--with-pcre=PATH时，需要从PCRE网站下载pcre库的源码（版本4.4 - 8.40）并解压，剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。\r\n- `--with-zlib=PATH` 指定zlib(1.1.3 — 1.2.11)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。\r\n- `--with-http_ssl_module` 使用https协议模块。默认情况下，该模块没有被构建。前提是openssl与openssl-devel已安装\r\n\r\n## 编译命令示例\r\n\r\n```\r\n./configure\r\n    --sbin-path=/usr/local/nginx/nginx\r\n    --conf-path=/usr/local/nginx/nginx.conf\r\n    --pid-path=/usr/local/nginx/nginx.pid\r\n    --with-http_ssl_module\r\n    --with-pcre=../pcre-8.40\r\n    --with-zlib=../zlib-1.2.11\r\n```\r\n# nginx使用\r\n- `sudo nginx` 启动\r\n- `sudo nginx -s reload` 重新加载配置文件\r\n- `sudo nginx -s stop` 快速停止nginx，可能不会保存相关信息 \r\n- `sudo nginx -s quit` 完整停止nginx，按照一定顺序进行停止，保存相关信息 \r\n\r\n# 示例及注解\r\n\r\n简单讲解常见的配置\r\n\r\n部分配置被选择性忽略😂\r\n\r\n```\r\n# nginx执行用户\r\nuser    nobody;\r\n# 工作进程数\r\nworker_processes    2;\r\n\r\n# 错误日志\r\nerror_log  logs/error.log;\r\n#error_log  logs/error.log  notice;\r\n#error_log  logs/error.log  info;\r\n\r\n# 在Linux/Unix下，很多程序比如nginx会启动多个进程，而发信号的时候需要知道要向哪个进程发信号。\r\n# 不同的进程有不同的pid（process id）。\r\n# 将pid写进文件可以使得在发信号时比较简单。比如要重新加载nginx的配置可以这样写kill -HUP `cat /path/to/nginx.pid`\r\n\r\npid        logs/nginx.pid;\r\n\r\nevents {\r\n    # 使用epoll的I/O模型(值得注意的是如果你不知道Nginx该使用哪种轮询方法的话，它会选择一个最适合你操作系统的)\r\n    use epoll;\r\n    \r\n    #工作进程的最大连接数量 理论上每台nginx服务器的最大连接数为worker_processes*worker_connections worker_processes为我们再main中开启的进程数\r\n    worker_connections  2048;\r\n}\r\n\r\nhttp {\r\n    # http下的配置\r\n    # 都可以在location中进行覆盖\r\n    # 如果location中没有，则使用http中的配置\r\n\r\n    include       mime.types;\r\n    default_type  application/octet-stream;\r\n\r\n    sendfile        on;\r\n\r\n    keepalive_timeout  65;\r\n\r\n    # gzip压缩功能设置\r\n    gzip on;\r\n    gzip_min_length 1k;\r\n    gzip_buffers    4 16k;\r\n    gzip_http_version 1.0;\r\n    gzip_comp_level 6;\r\n    gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;\r\n    gzip_vary on;\r\n\r\n    # http_proxy 设置\r\n    client_max_body_size   10m;\r\n    client_body_buffer_size   128k;\r\n    proxy_connect_timeout   75;\r\n    proxy_send_timeout   75;\r\n    proxy_read_timeout   75;\r\n    proxy_buffer_size   4k;\r\n    proxy_buffers   4 32k;\r\n    proxy_busy_buffers_size   64k;\r\n    proxy_temp_file_write_size  64k;\r\n    proxy_temp_path   /usr/local/nginx/proxy_temp 1 2;\r\n\r\n    # 设定负载均衡后台服务器列表 \r\n    upstream  backend  { \r\n              #ip_hash; \r\n              server   192.168.10.100:8080 max_fails=2 fail_timeout=30s ;  \r\n              server   192.168.10.101:8080 max_fails=2 fail_timeout=30s ;  \r\n    }\r\n\r\n    # 很重要的虚拟主机配置\r\n    server {\r\n        # 监听的端口和域名的配置\r\n        # 如果需要多个，空格分割\r\n        listen       80;\r\n        server_name example.com www.example.com;\r\n        \r\n        # 根目录配置\r\n        # 在没有另外配置的情况下\r\n        # 使用这里的配置\r\n        root   /path/to/root;\r\n        \r\n        charset utf-8;\r\n\r\n        # 对/所有做负载均衡+反向代理\r\n        location / {\r\n            index  index.php index.html index.htm;\r\n\r\n            proxy_pass        http://backend;  \r\n            proxy_redirect off;\r\n            # 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP\r\n            proxy_set_header  Host  $host;\r\n            proxy_set_header  X-Real-IP  $remote_addr;  \r\n            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;\r\n            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;\r\n\r\n        }\r\n\r\n        location ~ .*\\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {   \r\n            # 这里另外配置了root\r\n            # 所以处的root为下面配置的路径\r\n            root /path/to/img\r\n            \r\n            # expires指令可以控制HTTP应答中的\"Expires\"和\"Cache-Control\"的头标, 起到控制页面缓存的作用\r\n            expires      7d; \r\n        }\r\n    \r\n        location ~ ^/.git {   \r\n            deny all;   \r\n        }\r\n        #error_page  404              /404.html;\r\n\r\n        # 当status为50x的时候，也就是服务器错误的时候，进行跳转显示定义好的错误页/50x.html\r\n        error_page   500 502 503 504  /50x.html;\r\n        location = /50x.html {\r\n            root   /path/to/error_page;\r\n        }\r\n    }\r\n    \r\n    # 引入servers下所有conf结尾的文件作为配置文件\r\n    # 一般情况下是其他的server的配置\r\n    include servers/*.conf;\r\n}\r\n```\r\n\r\n"}}
{"actor":{"display_login":"faaaar"}}