写自己的nginx配置文件
前面几节中我们已经学过了nginx配置文件中的各个段的配置指令,下面我们就来写一个自己配置文件。如下代码:
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
location / {
#root html; #定义服务器的默认网站根目录位置
#index index.php index.html index.htm; #定义首页索引文件的名称
proxy_pass http://www.baidu.com;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
这样我们自己的配置文件就完成了,先将nginx的服务停止,然后我们用nginx -c .conf命令来重新启动nginx,.conf 为我们自己的配置文件所在的路径,nginx启动以后,然后点击【访问测试】,看看会出现什么情况,是不是已经转到我们所配置的站点了。
在右面的编辑页面中编辑一个配置文件,我自己的配置文件名为Mynginx.conf,其中的内容就是以上面代码的内容,保存在/etc/nginx目录下,完成以后我们做如下操作:
nginx -s stop
nginx -c /etc/nginx/Mynginx.conf
然后点击【访问测试】