美文网首页
centos配置nginx

centos配置nginx

作者: quchangTJU | 来源:发表于2019-11-07 12:36 被阅读0次

1.安装安装gcc gcc-c++

$ yum install -y gcc gcc-c++ 

2.安装wget

yum -y install wget

3.安装PCRE库

1.
$ cd /usr/local/
2.
$ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
3.安装tar
$ yum install -y tar
$ tar -zxvf pcre-8.33.tar.gz
4.
$ cd pcre-8.33
5.
$ ./configure
6.安装make
$ yum -y install gcc automake autoconf libtool make
7.
$ make && make install

4.安装ssl库

1.
$ cd /usr/local/
2.
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
3.
$ tar -zxvf openssl-1.0.1j.tar.gz
4.
$ cd openssl-1.0.1j
5.
$ ./config
6.
$ make && make install
7.

5.安装zlib

1.
$ cd /usr/local/
2.
$ wget http://zlib.net/zlib-1.2.11.tar.gz
3.
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
4.
./configure
5.
make && make install

6.安装nginx

1.
$ cd /usr/local/
2.
$ wget http://nginx.org/download/nginx-1.8.0.tar.gz
3.
$ tar -zxvf nginx-1.8.0.tar.gz
4.
$ cd nginx-1.8.0
5. 安装openssl
$ yum -y install openssl openssl-devel
6.
$ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
7.
$ make && make install

6.安装nginx之后会在/usr/local下生成nginx和nginx-1.8.0两个文件夹,启动的时候选择nginx/sbin/nginx启动

7.启动nginx

1.
$ /usr/local/nginx/sbin/nginx

如果报错,/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory,运行下列指令:

1.
$ ldd /usr/local/nginx/sbin/nginx
输出:
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000030e8400000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000030f9a00000)
libpcre.so.1 => not found时,
1.
$ ls /lib/ |grep pcre
输出:
libpcre.so.0
libpcre.so.0.0.1
2.
ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1
添加软连接完毕,运行:
$ /usr/local/nginx/sbin/nginx

8.如果部署在新浪云上,需要配置nginx监听5050端口,操作如下:
容器管理面板中打开云编辑器,编辑/usr/local/nginx/conf/nginx.conf文件,端口修改为5050,server_name添加你的应用域名(域名在应用设置/应用信息中查看,一般为XXX.applinzi.com):

    server {
        listen       5050;
        server_name  localhost XXX.applinzi.com;#XXX为你的应用名

9.nginx如果访问其他文件夹的静态文件,会出现403,原因是静态文件权限设置不正确,输入指令(777表示文件夹以及文件夹下所有文件和文件夹可读可写可执行):

$ chmod -R 777 /data1
#/data1替换成你所在静态文件的目录,

相关文章

网友评论

      本文标题:centos配置nginx

      本文链接:https://www.haomeiwen.com/subject/dyjmbctx.html