欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > Nginx >内容正文

Nginx

Nginx —— 用HTTP核心模块配置一个静态的Web服务器

发布时间:2025/10/17 Nginx 28 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Nginx —— 用HTTP核心模块配置一个静态的Web服务器 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

静态Web服务器的主要功能有NGX_HTTP_CORE_MODULE模块(HTTP框架的主哟奥成员)实现,当然,一个完整的静态Web服务器还有许多功能由其他的HTTP模块实现。

1》Web服务器的地址: 192.168.1.210
2》Web服务器端设置nginx的conf文件内容:

[root@localhost conf]# cat nginx.conf | grep -v '#'worker_processes 1;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 8080;server_name localhost;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}} }

3》启动nginx服务器(找到nginx的二进制文件):

[root@localhost conf]# /usr/local/nginx/sbin/nginx

查找方式:# whereis  nginx  (会显示 nginx的安装路径)

4》查看是否启动成功:

[root@localhost conf]# ps -aux | grep nginx root 34848 0.0 0.0 20748 1404 ? Ss 19:46 0:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 35739 0.0 0.0 23284 1768 ? S 20:52 0:00 nginx: worker process root 35749 0.0 0.0 112720 984 pts/1 S+ 20:54 0:00 grep --color=auto nginx

5》客户端测试地址: 192.168.1.93

打浏览器地址栏输入: http://192.168.1.210:8080/

注意: 这里一定要加conf文件中监听的端口,否则http默认监听80端口。

6》显示的页面内容:

[root@localhost sbin]# cat ../html/index.html <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;} </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p><p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p> </body> </html>

 

 

 

 

 注意:  Nginx —— nginx服务的基本配置(nginx.conf文件的详解)

总结

以上是生活随笔为你收集整理的Nginx —— 用HTTP核心模块配置一个静态的Web服务器的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。