nginx的安裝和部署

1. 安裝

nginx安裝

軟件包:nginx-1.3.2.tar.gz

安裝前先確定操作系統中pcre包是否已經安裝(rpm –qa | grep pcre*),若未安裝先加載包安裝,若已安裝則將壓縮包存放到/usr/local/目錄中,如:

#cd /usr/local/
#tar zxvf nginx-1.3.2.tar.gz
#cd /usr/local/ nginx-1.3.2
#./configure --prefix=/usr/local/nginx/ --with-http_stub_status_module 

若報錯:yum install -y zlib-devel

yum -y install openssl openssl-devel

#make
#make install

(若沒有加with-http_stub_status_module,則後續加入nginxstatus參數报unknown directive "stub_status"錯誤)

配置环境变量

在/etc/profile 中加入環境變量配置

 export NGINX_HOME=/usr/local/nginx   (使用whereis nginx查看nginx的家目錄)  
 export PATH=$PATH:$NGINX_HOME/sbin  

编译完保存退出并执行

source /etc/profile   
nginx -v

nginx version: nginx/1.10.2

nginx的使用管理

開啟:nginx -c conf/nginx.conf

重啟:nginx -s reload

關閉:nginx -s stop

默認頁面/usr/local/nginx/html/index.html

2.web服務器搭建

更改根目錄

server {
listen 80; #變更端口
server_name localhost; #以后要绑定域名的时候改这里
index index.php index.html index.htm;

    location / {
        root   /urs/share/nginx/hmtl; #这里是文件的根目录
        index  index.php 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; #这里是出50*错之后的展示页面位置
    }
    
    location ~ \.php$ {
        root           /usr/share/nginx/html; #这里也是文件的根目录(PHP)
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

}
記得重啟服務:

nginx -s reload

注意根目錄的訪問權限

3.搭建多站點

不同端口多站點

[root@ ]# vim /etc/nginx/nginx.conf

将虚拟目录的配置文件加入到”http {}”部分的末尾

http {
    ...
    include /etc/nginx/vhost/*.conf;
}

在此路徑下放在配置文件:

1.conf變更所需的端口或者域名、根目錄等即可

server {    
			 listen 80; # 监听端口     
			server_name www.siteA.com siteA.com;    # 站点域名     
			root  /home/user/www/blog;              # 站点根目录     
			index index.html index.htm index.php;   # 默认导航页       
			location / {         
					#WordPress固定链接URL重写         
					if (!-e $request_filename) {            
							rewrite (.*) /index.php;         
			}			     
		}       
			#PHP配置    
 			location ~ \.php$ {         
			fastcgi_pass unix:/var/run/php5-fpm.sock;         
			fastcgi_index index.php;         
			include fastcgi_params;     
			} 
		}


nginx -s reload

4.yum搭建nginx

需要epel.repo包

yum install -y nginx

配置文件在/etc/nginx/nginx.conf

默認頁面在/usr/share/nginx/html/index.html

然後使用systemctl 操作nginx服務

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值