日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Nginx 在centos linux 安装、部署完整步骤并测试通过

發布時間:2023/11/27 生活经验 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx 在centos linux 安装、部署完整步骤并测试通过 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

需要先裝pcre, zlib,前者為了重寫rewrite,后者為了gzip壓縮。

1.選定源碼目錄

選定目錄?/usr/local/

?

cd /usr/local/

2.安裝PCRE庫

cd /usr/local/

wget?http://exim.mirror.fr/pcre/pcre-8.02.tar.gz

tar -zxvf pcre-8.02.tar.gz

cd pcre-8.02

./configure && make ?&& make install

?

3.安裝zlib庫

cd /usr/local/?

wget?http://zlib.net/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

./configure

make

make install

?

4.安裝ssl

?

cd /usr/local/

wget?http://www.openssl.org/source/openssl-1.0.1c.tar.gz

tar -zxvf openssl-1.0.1c.tar.gz

./config

make

make install

?

5.安裝nginx

?

Nginx?一般有兩個版本,分別是穩定版和開發版,您可以根據您的目的來選擇這兩個版本的其中一個,下面是把?Nginx?安裝到?/usr/local/nginx?目錄下的詳細步驟:

?

cd /usr/local/

wget?http://nginx.org/download/nginx-1.2.8.tar.gz

tar -zxvf nginx-1.2.8.tar.gz

cd nginx-1.2.8??

./configure?--prefix=/usr/local/nginx?

make

make install

?

--with-pcre=/usr/src/pcre-8.21?指的是pcre-8.21?的源碼路徑。

--with-zlib=/usr/src/zlib-1.2.7?指的是zlib-1.2.7?的源碼路徑。

?

6.啟動

確保系統的?80?端口沒被其他程序占用,

/usr/local/nginx/sbin/nginx

?

檢查是否啟動成功:

netstat -ano|grep 80?有結果輸入說明啟動成功

?

?

打開瀏覽器訪問此機器的?IP,如果瀏覽器出現?Welcome to nginx!?則表示?Nginx?已經安裝并運行成功。

?

7.重啟

/usr/local/nginx/sbin/nginx –s reload

?

8.修改配置文件

cd /usr/local/nginx/conf

vi nginx.conf

?

9.常用配置

#nginx運行用戶和組

user????www www;??

#啟動進程,通常設置成和cpu的數量相等

worker_processes??4;

?

#全局錯誤日志及PID文件

pid /var/run/nginx.pid;

error_log? /var/log/nginx/error.log;

?

events {

????????#epoll是多路復用IO(I/O Multiplexing)中的一種方式,但是僅用于linux2.6以上內核,可以大大提高nginx的性能

use epoll;

???????????????????#單個后臺worker process進程的最大并發鏈接數

????????worker_connections??10240;

}

#設定http服務器,利用它的反向代理功能提供負載均衡支持

http {

????????include???????mime.types;

?

????????default_type??application/octet-stream;

?

?????????error_page 400 403 500 502 503 504??/50x.html;

?

????????index index.html index.shtml

?

????????autoindex off;

?

?????????fastcgi_intercept_errors on;

?

????????sendfile????????on;

?

????????# These are good default values.

????????tcp_nopush??????on;

????????tcp_nodelay?????off;

?

????????# output compression saves bandwidth

????????gzip??off;

?????????#gzip_static on;

????????#gzip_min_length??1k;

????????gzip_http_version 1.0;

????????gzip_comp_level 2;

????????gzip_buffers??4 16k;

????????gzip_proxied any;

????????gzip_disable "MSIE [1-6]\.";

????????gzip_types??text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;

????????#gzip_vary on;

?

????????server_name_in_redirect off;

?

#設定負載均衡的服務器列表

????????upstream portals {

??????????????????server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;

??????????????????server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;

????????????????????????????server 172.16.68.136:8082 max_fails=2 fail_timeout=30s;

??????????????????server 172.16.68.137:8082 max_fails=2 fail_timeout=30s;

????????}

?

????????#upstream overflow {

?????????#???????server 10.248.6.34:8090 max_fails=2 fail_timeout=30s;???????

?????????#???????server 10.248.6.45:8080 max_fails=2 fail_timeout=30s;???????

????????#}

?

????????server {

?????????????????????????????????????#偵聽8080端口

????????????????listen???????8080;

????????????????server_name??127.0.0.1;

?

???????????????????#403、404頁面重定向地址

???????????????????error_page??403 = http://www.e100.cn/ebiz/other/217/403.html;

???????????????????error_page??404 = http://www.e100.cn/ebiz/other/218/404.html;

???????????????????proxy_connect_timeout??????90;

???????????????????proxy_send_timeout?????????180;

???????????????????proxy_read_timeout?????????180;

?

???????????????????proxy_buffer_size 64k;

???????????????????proxy_buffers 4 128k;

???????????????????proxy_busy_buffers_size 128k;

?

?

???????????????????client_header_buffer_size 16k;

???????????????????large_client_header_buffers 4 64k;

?

????????????????#proxy_send_timeout?????????3m;

????????????????#proxy_read_timeout?????????3m;

????????????????#proxy_buffer_size??????????4k;

????????????????#proxy_buffers??????????????4 32k;

?

????????????????proxy_set_header Host $http_host;

????????????????proxy_max_temp_file_size 0;

????????????????#proxy_hide_header Set-Cookie;

??????????????????

?????????#???????if ($host != 'www.e100.cn' ) {

?????????#????????????????rewrite ^/(.*)$ http://www.e100.cn/$1 permanent;

?????????#???????}

?

?

???????????????location / {

???????????????????????deny all;

???????????????}

?

???????????????????location ~ ^/resource/res/img/blue/space.gif {

????????????????????proxy_pass http://tecopera;

???????????????}

?

???????????????location = / {

???????????????????rewrite ^(.*)$??/ebiz/event/517.html last;

???????????????}

?

?

?

???????????????????location = /ebiz/event/517.html {

????????????????????add_header Vary Accept-Encoding;

????????????????????root /data/web/html;

????????????????????expires 10m;

???????????????}

?

?

?

?

???????????????location = /check.html {

????????????????????root /usr/local/nginx/html/;

????????????????????access_log off;

???????????????}

?

???????????????location = /50x.html {

????????????????????root /usr/local/nginx/html/;

????????????????????expires 1m;

????????????????????access_log off;

???????????????}

?

?

??????????????location = /index.html {

???????????????????????add_header Vary Accept-Encoding;

#定義服務器的默認網站根目錄位置

????????????????????root /data/web/html/ebiz;

????????????????????expires 10m;

???????????????}

#定義反向代理訪問名稱

???????????????????location ~ ^/ecps-portal/* {

???????????????????# expires 10m;

#重定向集群名稱

????????????????????proxy_pass http://portals;

????????????????????#proxy_pass http://172.16.68.134:8082;

???????????????}

?

???????????????????location ~ ^/fetionLogin/* {

???????????????????# expires 10m;

????????????????????proxy_pass http://portals;

????????????????????#proxy_pass http://172.16.68.134:8082;

????????????????}

?

???????????????????#location??~ ^/business/* {??????????????????????????????????????????????????????????????????????

????????????????#???# expires 10m;????????????????????????????????????????????????????????????????????????????????

????????????????#????proxy_pass http://172.16.68.132:8088;???????????????????????????????????????????????????????????????????

????????????????#????#proxy_pass http://172.16.68.134:8082;???????????????????????????????????????????????????????

????????????????#}

?

???????????????????location ~ ^/rsmanager/* {

????????????????????expires 10m;

????????????????????root /data/web/;

????????????????????#proxy_pass http://rsm;

???????????????}

#定義nginx處理的頁面后綴

???????????????????location ~* (.*)\.(jpg|gif|htm|html|png|js|css)$??{

????????????????????????????root /data/web/html/;

#頁面緩存時間為10分鐘

?????????????????????????expires 10m;

???????????????????}

?

#設定查看Nginx狀態的地址?????

???????????????location ~* ^/NginxStatus/ {

????????????????????stub_status on;

????????????????????access_log off;

????????????????????allow 10.1.252.126;

????????????????????allow 10.248.6.49;

????????????????????allow 127.0.0.1;

????????????????????deny all;

???????????????}

?????????#???????error_page???405 =200 @405;

?????????#???????location @405

?????????#???????{

?????????#????????????????proxy_pass http://10.248.6.45:8080;

?????????#???????}??

?

???????????????access_log??/data/logs/nginx/access.log combined;

???????????????error_log???/data/logs/nginx/error.log;

????????}

?????????server {

????????????????listen???????8082;

?

????????????????server_name??_;

???????????????location = /check.html {

????????????????????root /usr/local/nginx/html/;

????????????????????access_log off;

???????????????}

??????????????????

????????}

?????????server {

???????????????????listen???????8088;

???????????????????server_name??_;

???????????????????location ~ ^/* {

???????????????????root /data/web/b2bhtml/;

???????????????????access_log off;

?????????}????????????????

?????????}

????????server {

????????????????listen???????9082;

????????????????server_name??_;

?

????????#????????location ~ ^/resource/* {

????????#????????????expires 10m;

?????????#???????????root /data/web/html/;

?????????#???????}

?

????????????????location??/ {

?????????????????????root /data/web/html/sysMaintain/;

???????????????????????if (!-f $request_filename) {

????????????????????????????rewrite ^/(.*)$ /sysMaintain.html last;

???????????????????????????}

????????????????}

????????}

?

}

轉載于:https://www.cnblogs.com/kool/p/6696086.html

總結

以上是生活随笔為你收集整理的Nginx 在centos linux 安装、部署完整步骤并测试通过的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。