ubuntu安装nginx

=========在线=============

sudo apt-get install nginx

nginx -v

sudo service nginx start

========离线=========

1.下载nginx-1.18.0.tar.gz

2. 解压

tar -zxvf nginx-1.18.0.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目录

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启动

 

posted @ 2022-03-24 16:31  jason47  阅读(3318)  评论(0编辑  收藏  举报