2 安裝Nginx前,須要先安裝 PCRE 庫 如已經安裝,請略過:php
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gzhtml
tar zxvf pcre-7.7.tar.gznginx
cd pcre-7.7瀏覽器
./configure服務器
makesession
make install
---------------------
做者:Tomcat貓
來源:CSDN
原文:https://blog.csdn.net/qq_34688380/article/details/78645126
版權聲明:本文爲博主原創文章,轉載請附上博文連接!app
三、安裝Nginxtcp
#yum update
更新一些庫和必要的支持,完了以後去下載一個nginx的最新版,現在我責編的版本是1.7.7:
#wget http://nginx.org/download/nginx-1.13.6.tar.gz
解壓縮
#tar -zvxf nginx-1.13.6.tar.gz
#cd nginx-1.13.6
nginx有不少不少編譯配置項,但因爲我這是第一篇筆記,因此我基本上都使用了默認的配置:
#./configure --with-http_ssl_module --with-http_gzip_static_module
我只加了兩個選項,--with-http_ssl_module表示使用ssl模塊,--with-http_gzip_static_module表示使用gzip模塊,其它更詳細的配置就要參考nginx的文檔了:http://nginx.org/en/docs/configure.htmlui若是沒configure成功(會顯示XXX not found),那是由於有些依賴沒有被正確安裝.那麼先安裝一下這些依賴條件,一般是pcre,zlib這些,這麼一下就基本上能夠了:
#yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-develspa#make
#make install可執行文件就會被安裝在: /usr/sbin/nginx (默認配置)
nginx基本使用
程序位置:/usr/local/nginx/sbin/nginx
配置文件位置:/usr/local/nginx/conf/nginx.conf
啓動nginx:
#cd /usr/local/nginx/sbin/
#./nginx若是運行的時候不帶-c參數,那就採用默認的配置文件,即/etc/nginx/nginx.conf
查看運行進程狀態:
# ps aux | grep nginx打開瀏覽器,訪問http://localhost/看看nginx的默認頁面:
中止nginx:
#./nginx -s stop重啓nginx(配置文件變更後須要重啓才能生效):
#./nginx -s reload檢查配置文件是否正確:
#./nginx -t查看nginx的pid:
cat /usr/local/nginx/logs/nginx.pid查看nginx版本
$ ./nginx -v回頭看編譯配置
# ./nginx -V
四、Nginx配置
#vi /usr/local/nginx/conf/nginx.conf
下面是設置兩個服務器
#user nobody; 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; upstream xxx.abc.com{ ip_hash; server xxx1.abc.com; server xxx2.abc.com:8989; } server { listen 80; server_name 127.0.0.1; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://xxx.abc.com; 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; #} } server { listen 6010; server_name 127.0.0.1; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://xxx.abc.com; 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; } } # 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; server_name 127.0.0.1; ssl on; ssl_certificate 1565150__abc.com.pem; ssl_certificate_key 1565150__abc.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { proxy_pass https://xxx.abc.com; root html; index index.html index.htm; } } }
參考:https://www.cnblogs.com/xiaoruilin/p/7782214.html