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启动
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2020-03-24 synchronized方法使用注意