Nginx配置文件详解

配置文件在 /etc/nginx/nginx.conf
nginx root目录修改报错403解决办法
chmod -R 755 目录(/usr/share/nginx/html)
修改nginx用户为其所有者
chown -R nginx_user:nginx_user /usr/share/nginx/html

View/Hide Code

更详细的配置在此:更多

多站点配置

在Nginx配置目录下,创建一个”vhost”目录。本例假设Nginx是默认安装,配置目录在”/etc/nginx”

mkdir /etc/nginx/vhost

创建siteA的配置文件

 vi /etc/nginx/vhost/test1.conf

配置文件内容

server {    listen       80;                        # 监听端口    server_name nginx1.shadowwu.club;    # 站点域名    root  /usr/share/nginx/html/nginx1.shadowwu.club;              # 站点根目录    index index.php index.html index.htm;   # 默认导航页    location / {        # WordPress固定链接URL重写        if (!-e $request_filename) {            rewrite (.*) /index.php;        }    }        error_page 404 /404.html;            location = /40x.html {        }        error_page 500 502 503 504 /50x.html;            location = /50x.html {        }        # 这里新加的        # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.        # Fastcgi服务器和程序(PHP,Python)沟通的协议.        location ~ \.php$ {            # 设置监听端口            fastcgi_pass   127.0.0.1:9000;            # 设置nginx的默认首页文件(上面已经设置过了,可以删除)            fastcgi_index  index.php;            # 设置脚本文件请求的路径            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            # 引入fastcgi的配置文件            include        fastcgi_params;        }}

新建站点根目录

mkdir /usr/share/nginx/html/nginx1.shadowwu.clubcd /usr/share/nginx/html/nginx1.shadowwu.clubvim index.php

引入站点配置文件

vim /etc/nginx/nginx.conf在http下末尾添加 include /etc/nginx/vhost/*.conf;http {    ...    include /etc/nginx/vhost/*.conf;}

重启nginx

systemctl restart nginx

配置dns解析后访问nginx1.shadowwu.club
出现返回application/octet-stream类型的数据
说明nginx的默认响应返回的Content-Type是application/octet-stream

打开配置文件

vim /etc/nginx/nginx.conf

修改

default_type application/octet-stream改为text/html

重启服务器

systemctl restart nginx

站点2配置

vi /etc/nginx/vhost/test2.conf
server {    listen       80;                        # 监听端口    server_name nginx2.shadowwu.club;    # 站点域名    root  /usr/share/nginx/html/nginx2.shadowwu.club;              # 站点根目录    index index.php index.html index.htm;   # 默认导航页    location / {        # WordPress固定链接URL重写        if (!-e $request_filename) {            rewrite (.*) /index.php;        }    }        error_page 404 /404.html;            location = /40x.html {        }        error_page 500 502 503 504 /50x.html;            location = /50x.html {        }        # 这里新加的        # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.        # Fastcgi服务器和程序(PHP,Python)沟通的协议.        location ~ \.php$ {            # 设置监听端口            fastcgi_pass   127.0.0.1:9000;            # 设置nginx的默认首页文件(上面已经设置过了,可以删除)            fastcgi_index  index.php;            # 设置脚本文件请求的路径            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            # 引入fastcgi的配置文件            include        fastcgi_params;        }}

新建站点2根目录

mkdir /usr/share/nginx/html/nginx2.shadowwu.clubcd  /usr/share/nginx/html/nginx2.shadowwu.clubvim index.php

重启服务器即可

systemctl restart nginx


©著作权归作者所有:来自51CTO博客作者寻儒的原创作品,如需转载,请注明出处,否则将追究法律责任

好知识,才能预见未来

赞赏

0人进行了赞赏支持

更多相关文章

  1. 系统默认语言与系统支持的语言列表
  2. 使用 IntraWeb (36) - TIWServerControllerBase
  3. 使用 IntraWeb (24) - 基本控件之 TIWFileUploader、TIWFile
  4. 使用 IntraWeb (23) - 基本控件之 TIWTimer、TIWProgressBar、TI
  5. zabbix监控默认的item key列表
  6. MySQL默认数据库介绍
  7. 记一次用WPScan辅助***WordPress站点
  8. 常用的 tailwindcss 模板站点
  9. .NetCore实践篇:分布式监控Zipkin持久化之殇

随机推荐

  1. CSS粘性定位是怎样工作的 [每日前端夜话0
  2. python格式化输出:%s和format()用法比较
  3. 对比MySQL学习Pandas的groupby分组聚合
  4. 教你用Python拆分表格并发送邮件
  5. 实战!半小时写一个脑力小游戏 [每日前端夜
  6. 干货!python与MySQL数据库的交互实战
  7. 用python数据分析了北京积分落户名单,发现
  8. Python22个构造函数法-助力数据挖掘与分
  9. 怎样开发可重用组件并发布到NPM [每日前
  10. Node.js多线程完全指南[每日前端夜话0x43