标签:index 配置文件 nginx html Nginx 详解 php fastcgi
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.club cd /usr/share/nginx/html/nginx1.shadowwu.club vim 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.club cd /usr/share/nginx/html/nginx2.shadowwu.club vim index.php
重启服务器即可
systemctl restart nginx
标签:index,配置文件,nginx,html,Nginx,详解,php,fastcgi 来源: https://blog.51cto.com/u_13640989/2753244
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。