fecshop nginx 的配置问题

技术分享 · water · 于 6年前 发布 · 3484 次阅读

nginx 发现有一些童鞋小白用起来还是费劲,下面分享一下:

下面是提问的内容:

到这里不会弄了...

再nginx.conf中

这么 配置对么? 其他的地址 每一个都配置一个server么?

回答:

1.安装nginx , 参看文档:http://www.fancyecommerce.com/2016/05/03/linux-安装nginx/

2.配置示例:

打开网盘:https://pan.baidu.com/s/1b63eXo#list/path=/tools

下载 usr.zip,然后解压 把 /usr/local/nginx/ 里面的所有文件夹以及文件上传到linux 的nginx的安装目录下(如果安装上面的文件安装,linux下的路径为 /usr/local/nginx/) , 然后,您修改 /usr/local/nginx/conf/conf.d/default.conf 即可。其他的不需要动

关于nginx的配置语法,如果一点也不了解,只能先学习nginx了。

共收到 12 条回复
water#16年前 0 个赞

一个例子说明:

server {
    listen     80  ;
	# server name 填写您的域名(ip也行),多个用空格隔开
    server_name fecshop.apphtml5.fancyecommerce.com fecshop.apphtml5.es.fancyecommerce.com;
	# 这个域名对应的文件根目录,也即是访问上面的域名,nginx会指向下面的目录(执行里面的相应的文件,默认是index文件)
    root  /www/web/develop/fecshop/apphtml5/web;
    server_tokens off;
    include none.conf;
	# 访问上面的域名,对于的root文件中默认执行的文件。优先级依次变低
    index index.php index.html index.htm;
	# nginx 访问日志 您需要新建该文件,并设置可写
    access_log /www/web_logs/access.log wwwlogs;
	# nginx 错误日志,您需要新建该文件,并设置可写
    error_log  /www/web_logs/error.log  notice;
	# 所有的.php 指向 php的fastcgi,127.0.0.1:9000 是默认的配置
    location ~ \.php$ {
                        fastcgi_pass   127.0.0.1:9000;
                        fastcgi_index  index.php;
                        include fcgi.conf;
        }
		# 图片文件访问的设置
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
                expires      30d;
        }
		# 对于 多语言  www.domain.com/fr 的配置,也就是把  www.domain.com/fr 作为根目录
         location /fr/ {
                index index.php;
                if (!-e $request_filename){
                        rewrite . /fr/index.php last;
                }
        }
		# 同上
         location /es/ {
                index index.php;
                if (!-e $request_filename){
                        rewrite . /es/index.php last;
                }
        }
		  location /cn/ {
                index index.php;
                if (!-e $request_filename){
                        rewrite . /cn/index.php last;
                }
        }

         location /de/ {
                index index.php;
                if (!-e $request_filename){
                        rewrite . /de/index.php last;
                }
        }

		# css和js的过期设置
        location ~ .*\.(js|css)?$ {
                expires      12h;
        }
		# 没用,magento之前残留的配置,可以去掉
        location /api {
                rewrite /api/([a-z][0-9a-z_]+)/?$ /api.php?type=$1;
         }


}

flighter#26年前 0 个赞

谢谢楼上 /usr/local/nginx/conf/conf.d/default.conf 已经配置好 当我在nginx.conf中添加

include /usr/local/nginx/conf/conf.d/*.conf; 之后 nginx无法启动

nginx.conf

user www www;
worker_processes auto;

error_log /data/wwwlogs/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;

events {
  use epoll;
  worker_connections 51200;
  multi_accept on;
}

http {
  include mime.types;
  default_type application/octet-stream;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 1024m;
  client_body_buffer_size 10m;
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 120;
  server_tokens off;
  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  fastcgi_intercept_errors on;

  #Gzip Compression
  gzip on;
  gzip_buffers 16 8k;
  gzip_comp_level 6;
  gzip_http_version 1.1;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
  open_file_cache max=1000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;

######################## default ############################
  server {
    listen 80;
    server_name _;
    access_log /data/wwwlogs/access_nginx.log combined;
    root /data/wwwroot/default;
    index index.php index.html index.htm ;
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    location /nginx_status {
      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }
    location ~ [^/]\.php(/|$) {
      #fastcgi_pass remote_php_ip:9000;
      fastcgi_pass unix:/dev/shm/php-cgi.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ /\.ht {
      deny all;
    }
  }
  
  include /usr/local/nginx/conf/conf.d/*.conf;

########################## vhost #############################
  include vhost/*.conf;
  
}
water#36年前 0 个赞
  1. 您的nginx安装,使用我上面的文档步骤安装

  2. 你用我百度云盘里面的配置吧,全部复制过去,然后修改 /usr/local/nginx/conf/conf.d/default.conf

flighter#46年前 0 个赞

nginx 现在没有问题了 hosts配置了 default.conf 也配置好了 但是浏览器访问 www.fecshoptest.com 显示 502 Bad Gateway 搞了两天, 求解...

flighter#56年前 0 个赞

nginx 现在没有问题了 hosts配置了 default.conf 也配置好了 但是浏览器访问 www.fecshoptest.com 显示 502 Bad Gateway 搞了两天, 求解...

water#66年前 0 个赞

@flighter #5楼 你先在@app/web/下面新建一个 22.php 随便写点代码,然后访问这个文件对应的url试试,看看,如果访问成功,那么说明nginx配置可以了,然后在找问题。

慢慢来吧,运维这些东西,都需要时间耗费在上面,慢慢磨出来。 会linux搭配环境,才能突破自己的技术瓶颈。

flighter#76年前 0 个赞

求救, 已经搞了一个星期, 其中各种重新搭建环境, 也找了几个人看, 但还是解决不了, hosts文件配置了, nginx.conf中也包含了conf.d/*.conf, default.conf 也配置好了, nginx可以正常访问其他页面, 但是输入www.fecshoptest.com就显示 502 bad gateway, 貌似始终无法跳转到default.conf

Fecmall#86年前 0 个赞

你在 www.fecshoptest.com
对应的路径下面的index.php 的顶部加上 echo 111;exit; 看看能访问不?

如果成功访问,说明 502 bad gateway 是php的错误,而不是nginx。然后你可以把断点持续的改变位置,看看问题出在哪里

如果访问失败,则说明是nginx有问题。

多考虑原理,然后各个点做试验,找出来问题所在。

flighter#96年前 0 个赞

将nginx.conf中的默认路径改成/www/web/fecshop/appfront/web, 访问ip可以显示echo111;exit; 但是www.fecshoptest.com访问就是502错误.

Maria#106年前 0 个赞

@flighter #9楼 这说明不是nginx配置出错,是php那个地方错了

你把 echo111;exit; 依次下移,看看到底哪行代码出错。找到代码行后,

你可以把 error_reporting(E_ALL || ~E_NOTICE); 这样代码先注释掉,查找问题。

然后把结果贴过来。

flighter#116年前 0 个赞

@Maria [#10楼](#comment10) 我将nginx.conf中的默认目录改回/home/wwwroot/default, 也有写include conf.d/*.conf, 但是www.fecshoptest.com访问显示502错误

Maria#126年前 0 个赞

@flighter #11楼 和你说了,你这个情况,是php的错误导致的,不是nginx配置的问题。好好看上面的回复。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics