a.上面博客說了在Linux中安裝nginx。
b.當Nginx安裝完畢后,會有相應的安裝目次,安裝目次里的nginx.confg為nginx的主設置文件,nginx主設置文件分為4部門,main(全局設置)、server(主機設置)、upstream(負載平衡處事器配置)以及location(URL匹配特定位置的配置),這四者的干系是:server擔任main,location擔任server,upstream既不會擔任其它配置也不會被擔任。
c.Nginx是一個署理處事器,一般環境下,網站是不能陳設在Nginx下的,好比用Java開拓的JavaWeb措施,我們陳設在tomcat下,然后利用Nginx署理將網址指向tomcat即可。
# kencery 注釋說明Nginx文件
# 時間:2016-1-19
# 進修內容,只是來自互聯網,有版權問題請接洽我刪除。
######## Nginx的main(全局設置)文件
#指定nginx運行的用戶及用戶組,默認為nobody
#user nobody;
#開啟的線程數,一般跟邏輯CPU核數一致
worker_processes 1;
#定位全局錯誤日志文件,級別以notice顯示,尚有debug,info,warn,error,crit模式,debug輸出最多,crir輸出最少,按照實際情況而定
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#指定歷程id的存儲文件位置
#pid logs/nginx.pid;
#指定一個nginx歷程打開的最多文件描寫符數目,受系統歷程的最大打開文件數量限制
#worker_rlimit_nofile 65535
events {
#配置事情模式為epoll,除此之外尚有select,poll,kqueue,rtsig和/dev/poll模式
#use epoll;
#界說每個歷程的最大毗連數,受系統歷程的最大打開文件數量限制。
worker_connections 1024;
}
#######Nginx的Http處事器設置,Gzip設置
http {
#主模塊指令,實現對設置文件所包括的文件的設定,可以淘汰主設置文件的巨大度,DNS主設置文件中的zonerfc1912,acl根基上都是用include語句。
include mime.types;
#焦點模塊指令,智力默認配置為二進制流,也就是當文件范例未界說時利用這種方法
default_type application/octet-stream;
#下面代碼為日志名目標設定,香港主機租用
香港高防服務器,main為日志名目標名稱,可自行配置,后頭引用
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#引用日志main
#access_log logs/access.log main;
#配置答允客戶端請求的最大的單個文件字節數
#client_max_body_size 20M;
#指定來自客戶端請求頭的headebuffer巨細
#client_header_buffer_size 32k;
#指定毗連請求試圖寫入緩存文件的目次路徑
#client_body_temp_path /dev/shm/client_body_temp;
#指定客戶端請求中較大的動靜頭的緩存最大數量和巨細,今朝配置為4個32KB
#large client_header_buffers 4 32k;
#開啟高效文件傳輸模式
sendfile on;
#開啟防備網絡阻塞
#tcp_nopush on;
#開啟防備網絡阻塞
#tcp_nodelay on;
#配置客戶端毗連生存勾當的超時時間
#keepalive_timeout 0;
keepalive_timeout 65;
#配置客戶端請求讀取超時時間
#client_header_timeout 10;
#配置客戶端請求主體讀取超時時間
#client_body_timeout 10;
#用于配置相應客戶端的超時時間
#send_timeout
####HttpGZip模塊設置
#httpGzip modules
#開啟gzip壓縮
#gzip on;
#配置答允壓縮的頁面最小字節數
#gzip_min_length 1k;
#申請4個單元為16K的內存作為壓縮功效流緩存
#gzip_buffers 4 16k;
#配置識別http協議的版本,默認為1.1
#gzip_http_version 1.1;
#指定gzip壓縮比,1-9數字越小,壓縮比越小,速度越快
#gzip_comp_level 2;
#指定壓縮的范例
#gzip_types text/plain application/x-javascript text/css application/xml;
#讓前端的緩存處事器進過gzip壓縮的頁面
#gzip_vary on;
#########Nginx的server虛擬主機設置
server {
#監聽端口為 80
listen 80;
#配置主機域名
server_name localhost;
#配置會見的語言編碼
#charset koi8-r;
#配置虛擬主時機見日志的存放路徑及日志的名目為main
#access_log logs/host.access.log main;
#配置虛擬主機的根基信息
location / {
#配置虛擬主機的網站根目次
root 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 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;
# }
#}
}
a.我在tomcat下陳設了一個javaweb項目,tomcat安裝的處事器IP為:192.168.37.136,陳設的項目在tomcat下的會見解點為:http://192.168.37.136:8080/lywh/
b.我在IP為192.168.37.133的處事器下面安裝樂成了Nginx。
c.那怎么樣將tomcat下陳設的網站利用Nginx署理呢?,修改Nginx的設置文件,修改呼吁:vim /usr/local/nginx/conf/nginx.conf