nginx配置模板问题

一、nginx主配置文件如下

cat /etc/nginx/nginx.conf
user nginx;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root /usr/local/nginx/html;
index index.php index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
location ~ \.php$ {
root /usr/local/nginx/html;
try_files $uri =;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} include vhosts/*;
##################################
}

二、简单的配置模板

/etc/nginx/vhosts/web.conf

server{
charset utf-;
listen ;
server_name 0.0.0.0;
# autoindex on;
# autoindex_exact_size off;
# autoindex_localtime on;
index index.html index.htm index.php;
location / {
root /data/www/web/;
# fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf; #allow 58.71.118.58;
#deny all;
}
location ~ \.php$ {
root /data/www/web/;
try_files $uri =;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
} }

经过测试,是可以正常使用的。但是今天开发的同事发现,在访问主页没有的问题的情况下,进一步访问页面中的内层页面的时候,发现提示404错误。

要么是权限问题,要么是模板配置不符合业务的配置要求。后来经过排查,因为开发自己的环境是没有问题,所以就干脆在他提供的配置文件上做了修改,问题解决。

配置模板如下:

server{
listen ;
server_name 0.0.0.0;
index index.html index.php;
large_client_header_buffers 16k;
client_max_body_size 300m;
client_body_buffer_size 128k;
proxy_connect_timeout ;
proxy_read_timeout ;
proxy_send_timeout ;
proxy_buffer_size 64k;
proxy_buffers 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
root /data/www/web/; location ~* \.(ico|css|js|gif|jpe?g|png)(\?[-]+)?$ {
expires max;
log_not_found off;
} location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

nginx配置模板问题404的更多相关文章

  1. GitLab 配置模板

    GitLab 配置模板 GitLab 使用模板和参数生成配置文件. 一般来说,我们会通过 gitlab.rb 文件修改配置,例如 Nginx 相关配置. gitlab.rb 只能使用特定的几个 Ngi ...

  2. nginx 配置全站404(百度闭站保护)

    在百度站长里申请闭站保护时,需要全站404.可能过nginx配置实现 location / {   #root html;   #index index.html index.htm;   retur ...

  3. NGINX 配置404错误页面转向

    什么是404页面 如果碰巧网站出了问题,或者用户试图访问一个并不存在的页面时,此时服务器会返回代码为404的错误信息,此时对应页面就是404页面.404页面的默认内容和具体的服务器有关.如果后台用的是 ...

  4. NGINX 配置404错误页面转向

    什么是404页面 如果碰巧网站出了问题,或者用户试图访问一个并不存在的页面时,此时服务器会返回代码为404的错误信息,此时对应页面就是404页面.404页面的默认内容和具体的服务器有关.如果后台用的是 ...

  5. Nginx配置error_page 404错误页面

    问题由来 昨天一网友在segmentfault.com上提问,无法做404重定向 打开对方的网站随便输入一个错误的地址发现给出了404代码,但是页面完全空白,并没有显示404页面的设定内容 当时就明白 ...

  6. nginx 配置Tp5项目时出现 404 Not Found nginx

    1.首先看了nginx报错日志 报 signal process started signal process started表示还有 产生原因 1.可能你的nginx.conf 内容配置的有问题. ...

  7. 记录一次 Nginx 配置 proxy_pass 后 返回404问题

    一. Nginx 配置 proxy_pass 后 返回404问题 故障解决和定位 1.1. 问题 在一次生产涉及多次转发的配置中, 需求是下面的图: 在配置好了 proxy_pass 之后,请求 ww ...

  8. Nginx 配置简述

    不论是本地开发,还是远程到 Server 开发,还是给提供 demo 给人看效果,我们时常需要对 Nginx 做配置,Nginx 的配置项相当多,如果考虑性能配置起来会比较麻烦.不过,我们往往只是需要 ...

  9. Nginx配置Https

    1.申请证书: https://console.qcloud.com/ssl?utm_source=yingyongbao&utm_medium=ssl&utm_campaign=qc ...

随机推荐

  1. PCIE

    ---恢复内容开始--- 高速差分总线.串行总线 每一条PCIe链路中只能连接两个设备这两个设备互为是数据发送端和数据接收端.PCIe链路可以由多条Lane组成,目前PCIe链路×1.×2.×4.×8 ...

  2. CF980E

    题面 Panel 国将举办名为数字游戏的年度表演.每个省派出一名选手. 国家有 n 个编号从 1 到 n 的省,每个省刚好有一条路径将其与其他省相连.第 i 个省出来的代表有 2^i 名粉丝. 今年, ...

  3. Nginx 阻塞与非阻塞

    L:32

  4. django---一对多和多对多字段的操作训练

    建表准备: django项目models.py建表 from django.db import models class Myclass(models.Model): cname = models.C ...

  5. POJ2763-Housewife Wind-树上单点修改区间求和

    这道题可以树链剖分做.但是最近在给学弟搞数据结构复习了LCA树状数组RMQ 然后就搞了一发LCA+树状数组维护. dis数组维护当前点到根节点的权值和.则dis(u,v) = dis[u]+dis[v ...

  6. Python内建GUI模块Tkinter(一)

    Python主窗口 Python特定的GUI界面,是一个图像的窗口,tkinter是python自带的,可以编辑的GUI界面,我们可以用GUI实现很多一个直观的功能,如何想开发一个计算器,如果只是一个 ...

  7. 【XSY2032】简单粗暴的题目 组合数

    题目描述 给你\(n,k,a_1\ldots a_n\),设 \[ ans_n=\sum_{i=1}^n{(\sum_{j=i}^ns(j))}^k\\ \] 求\(ans_1\ldots ans_n ...

  8. 【XSY2718】gift 分数规划 网络流

    题目描述 有\(n\)个物品,买第\(i\)个物品要花费\(a_i\)元.还有\(m\)对关系:同时买\(p_i,q_i\)两个物品会获得\(b_i\)点收益. 设收益为\(B\),花费为\(A\), ...

  9. project 2013 工时完成百分比不会自动更新填充

    [工时完成百分比].[实际完成百分比]  需要手填 [完成百分比] 会自动填,如下图

  10. Hdoj 4508.湫湫系列故事——减肥记I 题解

    Problem Description 对于吃货来说,过年最幸福的事就是吃了,没有之一! 但是对于女生来说,卡路里(热量)是天敌啊! 资深美女湫湫深谙"胖来如山倒,胖去如抽丝"的道 ...