Nginx安装使用和各种坑

首先安装环境很坑,如果是干净的安装环境主要是下面的三个开发包。

更新安装三个开发包分别是

方案一:(不要用)

Libs:
sudo apt-get zlib zlib-devel

Openssl:
sudo apt-get  openssl openssl-devel

Pcre:
sudo apt-get  install  pcre pcre-devel

Nginx:
Sudo apt-get install nginx就会自动安装

上面的方法不可取我们使用官网的方式每个包进行下载

方案二:

首先创建一个package文件夹
下载Libs
Wget https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz

下载 Openssl
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz

下载 Pcre
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.zip

下载nginx
wget http://nginx.org/download/nginx-1.8.0.tar.gz

解压:
tar -xvf pcre-8.00.tar.bz2
tar -zxvf openssl-1.0.1t.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
tar -zxvf nginx-1.8.0.tar.gz

把前三个按照下面的格式安装
sudo ./configure
sudo make
sudo make install

Nginx进行configure配置
配置说明参照这里:
https://www.cnblogs.com/fhen/p/6222105.html

按照自己的需求进行配置
我的配置为:

sudo ./configure  \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-pcre=/home/hy/package/pcre-8.40 \
--with-poll_module \
--with-http_flv_module \
--with-openssl=/usr/local/ssl 

进入配置的安装路径:

/usr/local/nginx
hy@ubuntu:/usr/local/nginx$ ls
conf  html  logs  sbin

查看配置文件如下,按照自己的需求进行配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

在浏览器输入 http://127.0.0.1

这里写图片描述

使用
打开:sudo nginx 或
sudo /usr/local/nginx/sbin/nginx

关闭:
sudo nginx -s stop 或
sudo nginx -s quit

重启:
nginx -s reload

问题点一:
libtool: compile: g++ -DHAVE_CONFIG_H -I. -c pcrecpp.cc -o .libs/pcrecpp.o
./libtool: line 990: g++: command not found
make[1]: * [pcrecpp.lo] Error 1
make[1]: Leaving directory `/home/hy/package/pcre-8.00’
make: * [all] Error 2

解决:apt-get install build-essential
apt-get install libtool

问题点二:
/bin/sh: line 2: ./config: No such file or directory
make[1]: * [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/usr/local/src/nginx-1.9.9’
make: * [build] Error 2

需要:https://www.cnblogs.com/huanhang/p/7580843.html

问题点三:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
解决:http://www.hankcs.com/appos/linux/fix-nginx-bind-err.html这个比较合理

猜你喜欢

转载自blog.csdn.net/qq_40062917/article/details/79159622