nginx在linux安装配置
重启 指令 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
linux版本:CentOS7 64位
【yum 安装最新版nginx:https://www.cnblogs.com/xxoome/p/7256214.html】
在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。
Linux下检查是否安装过某软件包:http://www.cnblogs.com/xxoome/p/5866553.html
安装命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
nginx下载地址:https://nginx.org/download/
下载“nginx-1.9.9.tar.gz”,移动到/usr/local/下。
复制代码
## 解压
tar -zxvf nginx-1.9.9.tar.gz
##进入nginx目录
cd nginx-1.9.9
## 配置
./configure --prefix=/usr/local/nginx
# make
make
make install
复制代码
OK,现在可以执行make 了。
执行make、make install命令
测试是否安装成功
# cd到刚才配置的安装目录/usr/loca/nginx/
./sbin/nginx -t
错误信息:
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
2016/09/13 19:08:56 [emerg] 6996#0: open() "/usr/local/nginx/logs/access.log" failed (2: No such file or directory)
原因分析:nginx/目录下没有logs文件夹
解决方法:
mkdir logs
chmod 700 logs
正常情况的信息输出:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动nginx
cd /usr/local/nginx/sbin
./nginx //启动nginx
//启动 命令
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
在浏览器中输入服务器的ip地址,如:192.168.1.12
很不幸,打不开链接。下面进行原因排查:
说明服务器的80端口是打不开的。
因为我使用的linux系统版本是CentOS7,所以可以在服务器中执行如下命令来验证》》
firewall-cmd --query-port=80/tcp
显然80端口没有开启。
下面我们开启80端口:
firewall-cmd --add-port=80/tcp --permanent
#重启防火墙
systemctl restart firewalld
--permanent #永久生效,没有此参数重启后失效
刷新浏览器
==========================================
配置完毕!
2、配置nginx开机自启动
vim /etc/rc.d/rc.local
2.nginx配置
安装教程
5.配置nginx.conf
**(注:*********代表服务器地址)
#
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;
server {
#监听的端口号
listen 80;
#设置访问的二级域名
server_name demo.eysource.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location /{
#配置访问的项目路径(注:这里重点)
proxy_pass http:********:9091/
# root html;
# index index.html index.htm;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
root html;
index index.html index.htm;
}
}
server {
#监听的端口号
listen 80;
#设置访问的二级域名
server_name aaa.eysource.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location /{
#配置访问的项目路径(注:这里重点)
proxy_pass http:********:8080/
# root html;
# index index.html index.htm;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
root html;
index index.html index.htm;
}
}
}
server {
listen 80;
server_name x.xxx.im; #你的域名
#charset koi8-r;
#access_log logs/host.access.log main;
location /api/v2 {
proxy_pass http:127.0.0.1:8888/api/v2; //你的项目地址端口
# root html;
# index index.html index.htm;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
root html;
index index.html index.htm;
}
}
4.参考博客
https://www.cnblogs.com/xxoome/p/5866475.html
https://www.cnblogs.com/pxstar/p/14808244.html
https://www.jb51.net/article/189935.htm
https://blog.csdn.net/dashuaigege642/article/details/84067731
不积跬步,无以至千里;不积小流,无以成江海。