標籤:

ubuntu nginx安裝、集成tomcat、動靜分離、集群、SSL卸載......

1. 安裝依賴

sudo apt-get install gcc

(一般都會有)

2.下載nginx ,並解壓並進入目錄

nginx.org/download/ngin

tar -xvf nginx-1.13.4.tar.gzcd nginx-1.13.4

(例:下載路徑為/home/ubuntu/nginx/nginx-1.13.4)

3.編譯和安裝(需手動添加ssl模塊編譯支持)

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_modulemakemake install

(安裝結束後安裝目錄:/usr/local/nginx)

4.自定義配置文件my.conf並配置tomcat集群、動靜分離、ssl

#以root用戶運行user root;worker_processes 4; #error_log logs/error.log;#error_log logs/error.log notice;error_log logs/error.log info; #pid logs/nginx.pid; events { #使用epoll模型提高性能 use epoll; 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 65; types_hash_max_size 2048; gzip on; gzip_min_length 1k; #最小1K gzip_buffers 16 64K; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain application/x-javascript text/css application/xml application/javascript; gzip_vary on; #負載均衡組 #靜態伺服器組 upstream nfc_tomcat { # tomcat 服務IP:port server 172.171.32.60:8080; } server { listen 8088 ssl; server_name localhost; # 密鑰創建: # mkdir /usr/local/nginx/ssl # cd /usr/local/nginx/ssl # openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /usr/local/nginx/ssl/nginx.key -out /usr/local/nginx/ssl/nginx.crt ssl_certificate /usr/local/nginx/ssl/nginx.crt; ssl_certificate_key /usr/local/nginx/ssl/nginx.key; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://nfc_tomcat; } # 所有靜態請求都由nginx處理,存放目錄為html location ~ .(gif|jpg|jpeg|png|bmp|swf|css|js|html)$ { # /usr/local/nginx 下新建static_info,並且創建 # 和java工程同名的路徑,如/NFCv1.0,將靜態資源搬進來,如整個view_admin文件夾 root static_info; } # 所有動態請求都轉發給tomcat處理 #location ~ .(jsp|do|html)$ { # proxy_pass http://nfc_tomcat; #} #error_page 500 502 503 504 /50x.html; # location = /50x.html { # root html; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.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 Apaches document root # concurs with nginxs one # #location ~ /.ht { # deny all; #} }}

5.各種命令 cd /usr/local/nginx/sbin

啟動: ./nginx -c /usr/local/nginx/conf/my.conf停止:./nginx -s stop版本:./nginx -V

推薦閱讀:

為什麼 node.js 的官網不用 node.js 而用 nginx 搭建?
8分鐘帶你深入淺出搞懂Nginx
新興的web伺服器caddy
CentOS 7 YUM 10分鐘快速安裝 LNMP 環
被頻繁攻擊訪問,nginx如何破解?

TAG:Nginx |