一,Nginx 简介
Nginx 是一个非常轻量级的HTTP服务器,Nginx,它的发音为“engine X”, 是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服务器。
二,ubuntu 上的安装过程
1,安装nginx服务
sudo apt-get install nginx
2,修改http访问时配置
/etc/nginx/sites-available/default 默认为80,我已修改为8086
$ sudo vim /etc/nginx/sites-available/default
修改目录,搭建成功后默认路径为/var/www/html/,将其修改为任意一个目录
3,重新开启nginx服务
sudo systemctl restart nginx.service
另一种重启方式:
$ sudo /etc/init.d/nginx restart
Restarting nginx (via systemctl): nginx.service.
查看端口是否生效:
未显示PID等信息,使用sudo
4,测试环境是否成功
网页端输入地址以及端口:例如:http://10.xx.xx.xx:8086/
此处信息为html 中已修改的(从下面可以可以看到,目录已更改为/dataServer)
$ cat /dataServer/index.debian.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to data update!</h1>
<p>更新目录.</p>
<p>For online documentation and support please refer to
<p><em>Thank you for using.</em></p>
</body>
</html>
5,遇到问题记录
有些版本系统配置/etc/nginx/sites-available/default 不起作用,是否自定义配置,查询方法:
通过查询
$ sudo systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-12-03 11:15:55 CST; 23min ago
Docs: man:nginx(8)
Process: 29788 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 29798 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 29799 (nginx)
Tasks: 33 (limit: 154451)
Memory: 26.7M
CGroup: /system.slice/nginx.service
├─29799 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─29800 nginx: worker process
├─29801 nginx: worker process
├─29802 nginx: worker process
├─29803 nginx: worker process
├─29804 nginx: worker process
├─29805 nginx: worker process
├─29806 nginx: worker process
├─29808 nginx: worker process
├─29809 nginx: worker process
├─29810 nginx: worker process
├─29812 nginx: worker process
├─29813 nginx: worker process
├─29814 nginx: worker process
├─29816 nginx: worker process
├─29817 nginx: worker process
├─29818 nginx: worker process
├─29820 nginx: worker process
├─29821 nginx: worker process
├─29822 nginx: worker process
├─29824 nginx: worker process
├─29825 nginx: worker process
├─29826 nginx: worker process
├─29827 nginx: worker process
├─29828 nginx: worker process
├─29829 nginx: worker process
├─29830 nginx: worker process
├─29831 nginx: worker process
├─29832 nginx: worker process
├─29833 nginx: worker process
├─29834 nginx: worker process
├─29835 nginx: worker process
└─29836 nginx: worker process
Dec 03 11:15:55 yjy systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 03 11:15:55 yjy systemd[1]: Started A high performance web server and a reverse proxy server.
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
最终找到
$ ls /etc/nginx/sites-available/ -lh
total 8.0K
-rw-r--r-- 1 root root 467 Aug 26 12:28 dataServer
-rw-r--r-- 1 root root 2.4K Dec 3 11:00 default
可以看到它才是生效的那个配置。