如何配置nginx
发布时间 - 2019-06-12 00:00:00 点击率:次在nginx安装完成的前提下,我们给大家介绍如何配置nginx。
Nginx配置的方法:
创建 Nginx 运行使用的用户 www:
[root@bogon conf]# /usr/sbin/groupadd www [root@bogon conf]# /usr/sbin/useradd -g www www
配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容
[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.conf user www www; worker_processes 2; #设置值和CPU核心数一致 error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别 pid /usr/local/webserver/nginx/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; #下面是server虚拟主机的配置 server { listen 80;#监听端口 server_name localhost;#域名 index index.html index.htm index.php; root /usr/local/webserver/nginx/html;#站点目录 location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d; # access_log off; } location ~ .*\.(js|css)?$ { expires 15d; # access_log off; } access_log off; } }
检查配置文件nginx.conf的正确性命令:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
启动 Nginx
Nginx 启动命令如下:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx
访问站点
从浏览器访问我们配置的站点ip:
Nginx 其他命令
以下包含了 Nginx 常用的几个命令:
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件 /usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx /usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
更多Nginx相关知识,请访问Nginx使用教程栏目!
# nginx
# 配置文件
# 几个
# 给大家
# 重启
# 相关知识
# 虚拟主机
# 前提下
# 数一
# 包含了
# descriptors
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
网站视频制作书签怎么做,ie浏览器怎么将网站固定在书签工具栏?
nodejs redis 发布订阅机制封装实现方法及实例代码
Laravel如何发送邮件和通知_Laravel邮件与通知系统发送步骤
微博html5版本怎么弄发超话_超话进入入口及发帖格式要求【教程】
关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)
QQ浏览器网页版登录入口 个人中心在线进入
Laravel如何处理和验证JSON类型的数据库字段
微信小程序 五星评分(包括半颗星评分)实例代码
LinuxShell函数封装方法_脚本复用设计思路【教程】
如何在局域网内绑定自建网站域名?
JS经典正则表达式笔试题汇总
如何选择PHP开源工具快速搭建网站?
iOS验证手机号的正则表达式
Python结构化数据采集_字段抽取解析【教程】
logo在线制作免费网站在线制作好吗,DW网页制作时,如何在网页标题前加上logo?
MySQL查询结果复制到新表的方法(更新、插入)
深圳网站制作设计招聘,关于服装设计的流行趋势,哪里的资料比较全面?
Laravel如何实现数据库事务?(DB Facade示例)
深圳网站制作培训,深圳哪些招聘网站比较好?
北京的网站制作公司有哪些,哪个视频网站最好?
深圳网站制作平台,深圳市做网站好的公司有哪些?
Laravel如何实现API版本控制_Laravel版本化API设计方案
Win11搜索不到蓝牙耳机怎么办 Win11蓝牙驱动更新修复【详解】
Google浏览器为什么这么卡 Google浏览器提速优化设置步骤【方法】
Laravel如何与Docker(Sail)协同开发?(环境搭建教程)
在线制作视频网站免费,都有哪些好的动漫网站?
C++时间戳转换成日期时间的步骤和示例代码
微信小程序 input输入框控件详解及实例(多种示例)
北京企业网站设计制作公司,北京铁路集团官方网站?
手机网站制作平台,手机靓号代理商怎么制作属于自己的手机靓号网站?
Laravel与Inertia.js怎么结合_使用Laravel和Inertia构建现代单页应用
Laravel如何实现多级无限分类_Laravel递归模型关联与树状数据输出【方法】
如何在IIS7上新建站点并设置安全权限?
宙斯浏览器文件分类查看教程 快速筛选视频文档与图片方法
如何有效防御Web建站篡改攻击?
Laravel如何配置Horizon来管理队列?(安装和使用)
Laravel如何从数据库删除数据_Laravel destroy和delete方法区别
制作ppt免费网站有哪些,有哪些比较好的ppt模板下载网站?
UC浏览器如何切换小说阅读源_UC浏览器阅读源切换【方法】
使用C语言编写圣诞表白程序
Laravel怎么创建控制器Controller_Laravel路由绑定与控制器逻辑编写【指南】
b2c电商网站制作流程,b2c水平综合的电商平台?
Android实现代码画虚线边框背景效果
Thinkphp 中 distinct 的用法解析
Android使用GridView实现日历的简单功能
php打包exe后无法访问网络共享_共享权限设置方法【教程】
,南京靠谱的征婚网站?
Laravel如何处理CORS跨域请求?(配置示例)
Laravel如何设置自定义的日志文件名_Laravel根据日期或用户ID生成动态日志【技巧】
详解Android图表 MPAndroidChart折线图


og crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
#下面是server虚拟主机的配置
server
{
listen 80;#监听端口
server_name localhost;#域名
index index.html index.htm index.php;
root /usr/local/webserver/nginx/html;#站点目录
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
location ~ .*\.(js|css)?$
{
expires 15d;
# access_log off;
}
access_log off;
}
}