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. codeforces616B

    Dinner with Emma CodeForces - 616B Jack decides to invite Emma out for a dinner. Jack is a modest st ...

  2. Nginx log_format

    L11 nginx 官网的日志格式如下 log_format compression(自定义名称) '$remote_addr - $remote_user [$time_local] ' '&quo ...

  3. codeforces1045B Space Isaac 【manacher】【差分】

    题目大意: 题目是将$[0,m)$的数划成了两个集合,其中一个集合的元素个数不超过$n$.问在第一个集合中选出的数加上第二个集合中选出的数的和中没有出现的数有哪些. 题目分析: 很有意思的一道题.方便 ...

  4. re 正则表达式

    简介: 1.一堆带有特殊意思的符号组成的式子它的作用 处理(匹配 查找 替换) 字符串 2.在爬虫中大量使用 其实有框架帮你封装了这些复杂的正则 3.在网站和手机APP注册功能中大量使用,例如判断你的 ...

  5. 【XSY1529】小Q与进位制 分治 FFT

    题目大意 ​ 小Q发明了一种进位制,每一位的变化范围是\(0\)~\(b_i-1\),给你一个这种进位制下的整数\(a\),问你有多少非负整数小于\(a\).结果以十进制表示. ​ \(n\leq 1 ...

  6. Codeforces 346D Robot Control(01BFS)

    题意 有一个 \(N\) 个点, \(M\) 条边的有向图, 初始有一个机器人在 \(1\) 号点. 每个时刻, 这个机器人会随机选择一条从该点出发地边并通过.当机器人到达点 \(N\) 时, 它就会 ...

  7. 自学华为IoT物联网_09 OceanConnect业务流程

    点击返回自学华为IoT物流网 自学华为IoT物联网_09 OceanConnect业务流程 1.  物流网重要的连个协议介绍 1.1  重要物联网协议介绍----MQTT MQTT(消息队列遥测传输) ...

  8. 【BZOJ4061】[Cerc2012]Farm and factory(最短路,构造)

    [BZOJ4061][Cerc2012]Farm and factory(最短路,构造) 题面 BZOJ 然而权限题QwQ. 题解 先求出所有点到达\(1,2\)的最短路,不妨记为\(d_{u,1}, ...

  9. Redhat 用代理连外网

    设置 /etc/yum.conf 添加proxy=http://web-proxy.corp.xx.com:8080 /etc/yum.repos.d/rhel-source.repo 里面改成ena ...

  10. 【git】git一些命令使用记录

    目前git版本控制很多公司都在用,我把平时的使用做些记录,防止忘记. 1. 有时候分支比较多,我们会基于master建立一个新分支开发,有时候也会基于别的分支建立,但时间长了可能会忘记当前分支是基于哪 ...