nginx 配置


nginx 配置

1.怎么查看nginx配置有什么錯誤?

在/usr/local/nginx/sbin目錄下

執行nginx -t  查看配置錯誤信息;

nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2016/10/24 11:44:09 [warn] 4303#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:1
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
2016/10/24 11:44:09 [emerg] 4303#0: open() "/var/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

 2.查看nginx的工作進程

ps aux|grep nginx

root 1880 0.0 0.2 33376 5392 ? Ss 10:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www 2404 0.0 1.6 57952 30180 ? S 10:37 0:00 nginx: worker process
wenfang 4383 0.0 0.0 112648 976 pts/0 S+ 12:07 0:00 grep --color=auto nginx

worker processes 1;一般設置為cpu數*核數;

3.nginx重載.conf配置

到nginx/sbin 下執行nginx -s reload
或者service nginx -s reload

4.nginx.conf配置詳解

user www www;
worker_processes 2;
  
error_log logs /error .log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
  
pid logs /nginx .pid;
  
  
events {
一般是nginx連接特性
如:有個worker可以允許多少個連接
use epoll;
worker_connections 2048;
}
  
/**這是配置http的主要段; 
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 65;
  
# gzip壓縮功能設置
gzip  on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 6;
gzip_types text /html  text /plain  text /css  text /javascript  application /json  application /javascript  application /x-javascript  application /xml ;
gzip_vary on;
  
# http_proxy 設置
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 75;
proxy_send_timeout 75;
proxy_read_timeout 75;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /usr/local/nginx/proxy_temp  1 2;
  
# 設定負載均衡后台服務器列表
upstream backend {
#ip_hash;
server 192.168.10.100:8080 max_fails=2 fail_timeout=30s ;
server 192.168.10.101:8080 max_fails=2 fail_timeout=30s ;
}
  
# 很重要的虛擬主機配置
server {
listen 80;  /*監聽80端口
server_name itoatest.example.com;  /*域名
root /apps/oaapp ;   /*指向項目目錄
  
charset utf-8;
access_log logs /host .access.log main;
  
#對 / 所有做負載均衡+反向代理
location /  {
root /apps/oaapp ;
index index.jsp index.html index.htm;
  
proxy_pass http: //backend ;
proxy_redirect off;
# 后端的Web服務器可以通過X-Forwarded-For獲取用戶真實IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
  
}
  
#靜態文件,nginx自己處理,不去backend請求tomcat
location ~* /download/  {
root /apps/oa/fs ;
  
}
location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /apps/oaapp ;
expires 7d;
}
location /nginx_status  {
stub_status on;
access_log off;
allow 192.168.10.0 /24 ;
deny all;
}
  
location ~ ^/(WEB-INF)/ {
deny all;
}
#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;
}
}
  
## 其它虛擬主機,server 指令開始
}

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM