Nginx教程
- 安装Nginx
sudo apt-get updat #更新软件包
sudo apt-get install nginx -y # 安装Nginx
- 启动Nginx服务
systemctl start nginx /etc/init.d/nginx start
- 查看Nginx状态
systemctl status nginx/etc/init.d/nginx statushtop #在列表中查找“nginx 主进程”和“nginx 工作进程”。如果您在列表中看到这些进程,则 Nginx 正在运行。
- 重启Nginx服务
每当您更改 Nginx 配置文件时,您都需要重新启动 Nginx。使用以下命令重新启动 Nginx:
systemctl restart nginx/etc/init.d/nginx restartservice nginx reload
如果你的配置文件有错误,重启 Nginx 将会失败。重启命令会在它输出的行的末尾写一个的“OK”或“Fail”,让你知道重启是失败还是成功。如果有错误,请更正,
然后重新启动 Nginx。然后它应该再次工作。
5. 停止Nginx服务
systemctl stop nginx/etc/init.d/nginx stop
启动Nginx服务后,在浏览器输入Ip地址即可(Nginx默认80端口)
- 配置Nginx
Nginx 主配置文件位于:
/etc/nginx/nginx.conf
Nginx 配置文件可能包含其他配置文件。因此,您可以将配置分成多个较小的、可重用的配置文件,这些文件都包含在 Nginx 主配置文件中。
要配置 Nginx,我们必须对 Nginx 配置文件进行更改。在更改之前制作原始配置文件的副本。这样,您可以随时返回原件,以防您弄乱副本。以下是复制原始 Nginx 配置文件的方法:
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
7. 部署网页
Nginx默认网页存放位置是 ```Linux
/var/www/html/index.nginx-debian.html
#默认网页文件,可通过修改/etc/nginx/sites-enabled/default,改变默认位置
可以使用远程连接工具,将默认文件替换成自己所编写的网页代码。
如果改变Nginx的默认配置,可以通过修改配置文件,文件位置为:
/etc/nginx/sites-enabled/default
server {listen 80 default_server; #默认IPV4的监听端口listen [::]:80 default_server; #默认IPV6的监听端口# SSL configuration## listen 443 ssl default_server;# listen [::]:443 ssl default_server;## Note: You should disable gzip for SSL traffic.# See: https://bugs.debian.org/773332## Read up on ssl_ciphers to ensure a secure configuration.# See: https://bugs.debian.org/765782## Self signed certs generated by the ssl-cert package# Don't use them in a production server!## include snippets/snakeoil.conf;root /var/www/html; #默认网页文件位置# Add index.php to the list if you are using PHPindex index.html index.htm index.nginx-debian.html;