1、更新软件源重点,否则会报安装失败
sudo apt-get update
2、安装nginx
sudo apt-get install nginx
安装好的文件位置:
/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志
3、修改nginx配置
vi /etc/nginx/sites-enabled/default
注意,修改/etc/nginx/nginx.conf会不起作用,这里具体配置啥的,我也不知道
进入后,修改端口及默认静态文件夹
我将端口从80改为了8000;默认静态文件夹由/var/www/html改为了/usr/share/nginx/html
listen 8000 default_server;root /usr/share/nginx/html;# 将接口请求中含 web、atom-host的请求转发到80端口location /web {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.proxy_pass http://127.0.0.1;}location /atom-host {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.proxy_pass http://127.0.0.1;}
4、重启nginx服务
/etc/init.d/nginx reloadsudo /etc/init.d/nginx restart
贴一些常用命令
vi /var/log/nginx/error.log +//打开错误日志并跳转到最后一行/etc/init.d/nginx reload 重载ngnix服务netstat -ntulp | grep 80 查看80端口占用情况