1.下载nginx-1.18.0.tar.gz

wget http://nginx.org/download/nginx-1.23.2.tar.gz

2. 解压

tar -zxvf nginx-1.23.2.tar.gz

3. 依次安装3个依赖pcre zlib openssl

sudo apt-get install libpcre3 libpcre3-dev

sudo apt-get install zlib1g-dev

sudo apt-get install openssl libssl-dev

在安装openssl时出现错误

Err:1 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.16   404  Not Found

解决:

sudo apt-get update

然后再重新 sudo apt-get install openssl libssl-dev

4. 进入nginx目录,安装配置nginx

./configure --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module

默认配置安装在/usr/local/nginx目录

注意:

checking for C compiler .. not found

./configure: error: C compiler cc is not found

如果出现上面这种检查不通过,则说明缺少某些依赖。

执行以下命令:

sudo apt-get install build-essential

5. 安装

sudo make && sudo make install

 

6. 查看版本

/usr/local/nginx/sbin/nginx -v

 

7.配置服务/lib/systemd/system/nginx.service

复制代码
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=-/sbin/local/nginx/sbin/nginx -s stop
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target
复制代码

保存退出后systemctl daemon-reload

服务操作

systemctl enable nginx.service 设置开机启动

systemctl start nginx.service

systemctl restart nginx.service

 

8.配置文件/usr/local/nginx/conf/nginx.conf

复制代码
worker_processes  auto;

pid /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    ##
    # Logging Settings
    ##
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" - '
                      '"$request_method $scheme://$host$uri $server_protocol"'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log;//这里会被下面覆盖,可以直接在下面配置
    error_log /var/log/nginx/error.log;

    sendfile        on;

    keepalive_timeout  65;

    server {
       # listen       80;
        listen       80 default_server;
        listen [::]:80 default_server;
        #server_name  localhost;
        root /home/nuctech/robotResume/webResume;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            try_files $uri $uri/ =404;
        }

       access_log /var/log/nginx/resume/access.log main;

        #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;
        }
    }
}
复制代码

 

systemctl start nginx.service启动

 

 
 
 转自:https://www.cnblogs.com/anenyang/p/16050365.html