nginx 初尝试
2016-06-17 20:17
405 查看
Nginx功能
nginx至少具有一个部署静态资源的功能,默认部署端口为80, 通过配置nginx还可同时监听其他端口。nginx可以用来做静态资源服务器,部署html、图片等静态资源。(通过一个php库还可以部署php,具体怎么搞还没有弄,java web项目是部署不了了,只能在nginx转发请求到java web服务器);用来做请求转发(反向代理),如果转发给内网服务器就叫内网映射,如果一个端口配置可转发到多个域就是负载均衡。Nginx配置
nginx的配置文件是nginx.conf, 我的nginx是用arch的yaourt命令安装的,配置文件被安装到了/etc/nginx/nginx.conf, nginx具有一个默认监听服务(80端口),配置文件在http节点下面。如果还想配置其他端口的监听可以平行http端口再设置Server节点,如下是我的一个nginx.conf配置文件: 注意server_name只是一个名称而已,不具有其他意义,刚开始我还以为nginx反向代理会涉及三个服务器一个是无法访问内网的公网ip服务器(如阿里云),第二个是内网nginx服务器,第三个是内网其他服务器 (内网服务器都没有公网ip), server_name就是用来设置公网ip服务器的, 显然这种认为是错的, nginx反向代理只涉及两个服务器,第一个是具备公网ip的内网服务器上面跑nginx服务,另一个就是内网其他服务器(不具备公网ip)。#user html;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 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root /usr/share/nginx/html;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 /usr/share/nginx/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 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;# }#}server {listen 81;server_name localhost;location / {#设置主机头和客户端真实地址,以便服务器获取客户端真实IPproxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#禁用缓存proxy_buffering off;#反向代理的地址proxy_pass http://localhost:8080; }}}
相关文章推荐
- Nginx reopen reload作用及工作过程
- 我的nginx+php是如何配置的?
- nginx 服务器重启命令 关闭
- Nginx rewrite
- Nginx配置文件(nginx.conf)配置详解
- Nginx服务器的搭建
- nginx开发常用
- LNMP 配置NGINX 支持THINKPHP PATHINFO模式
- nginx if多条件判断
- 如何在在阿里云服务器(ECS)上搭建nginx服务器?
- nginx服务
- Nginx服务器中配置GeoIP模块来拦截指定国家IP
- web环境搭建之Linux--nginx-php-mysql
- ha高可用集群----nginx
- nginx 出现413 Request Entity Too Large问题的解决方法
- Zabbix-3.0环境搭建指南
- laravel nginx配置
- windows下nginx安装、配置与使用
- nginx源码分析——模块
- nginx 使用小结