采用安装包进行安装
-
useradd leyou
-
cd /home/leyou
-
上传文件到
/home/leyou
-
本机上传到服务器可采用 scp -r nginx所在本地目录 服务器目录地址
eg:
scp -r D://test/nginx-1.10.0.tar.gz root@192.168.43.32:/home/leyou
-
解压
tar xvf nginx-1.10.0.tar.gz
-
进入 nginx-1.10.0目录
cd /home/leyou
-
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
-
make && make install
成功后的最后面的一句话make[1]: Leaving directory /home/leyou/nginx-1.10.0
出现的问题及解决的办法:
yum -y install gcc gcc-c++ autoconf automake make
checking for OS
+ Linux 3.10.0-1062.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
yum -y install pcre-devel
./configure: error: the HTTP gzip module requires the pcre rary.
yum install -y zlib-devel
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib
library
statically from the source with nginx by using –with-zlib=<path> option.
nginx
(如果80端口被占用则开启不了)- 查看服务
ps -ef | grep nginx
root 7787 1 0 16:32 ? 00:00:00 nginx: master process nginx
nobody 7788 7787 0 16:32 ? 00:00:00 nginx: worker process
root 7790 1795 0 16:32 pts/0 00:00:00 grep --color=auto nginx
kill -9 进程号
杀死
nginx的配置:
server {
listen 80;
server_name manage.leyou.com;
proxy_set_header X-Forworded-Host $host;
proxy_set_header X-Forworded-Server $host;
proxy_set_header X-Forworded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://192.168.43.30:9001; //拦截并代理到一个你指定的网址
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
nginx -s reload
重启nginx
nginx在root目录下访问文件:
user root; //使用用户的权限----第一行
#前端
location / {
#解决请求头失效
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root /root/ybx/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}