JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

centos7 安装配置nginx环境

wys521 2024-09-09 12:11:19 精选教程 37 ℃ 0 评论

Nginx 安装

1:下载nginx最新稳定版本:nginx-1.14.0.tar.gz,下载地址

http://nginx.org/en/download.html

2:执行 tar -zxvf nginx-1.14.0.tar.gz 如下图:

3:执行 cd nginx-1.14.0

4:执行 ./configure 出现如下错误:

5:执行 yum -y install gcc gcc-c++

6:继续执行 ./configure 出现如下错误(缺失pcre库):

7:执行 yum -y install pcre-devel

8:继续执行 ./configure 出现如下错误(缺失zlib库):

9:执行 yum -y install zlib-devel 结果如下图:

10:执行 make && make install

11:这时会发现在nginx-1.14.0同目录下生生成了nginx目录

12:执行 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 启动nginx 启动后如下图:

13:访问测试:浏览器输入http://ip 测试如下图:

14:其他命令:

重启:

/usr/local/nginx/sbin/nginx -s reload

停止:

/usr/local/nginx/sbin/nginx -s stop

检测配置文件是否正常:

/usr/local/nginx/sbin/nginx -t

Nginx 环境配置

server模块:

location匹配规则:location [=|~|~*|^~] /uri/ { … }

=普通字符精确匹配;

~正则匹配,区分大小写;

~*正则匹配,不区分大小写;

^~普通字符匹配,多用来匹配目录;

例如:

upstream tomcatweb_1{
	server 192.168.9.158:8080; 
}
server {
 listen 80 ;
 server_name lby.zyxr.com;
 location / {
 root /usr/local/nginx/html/web;
 }
 location /wap/ {
 alias /usr/local/nginx/html/wap/;
 }
 location /admin/ {
 alias /usr/local/nginx/html/admin/;
 }
 location /activity/ {
 alias /usr/local/nginx/html/activity/;
 }
 location /wapactivity/ {
 alias /usr/local/nginx/html/wapactivity/;
 }
 location /g1/M00 {
 root /usr/local/fastdfs/data/M00;
 ngx_fastdfs_module;
 }
 location ~* \.json$ {
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
 proxy_pass http://tomcatweb_1;
 }	
}

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表