doule0941 2015-01-31 14:38
浏览 70
已采纳

nginx没有加载(包括additional-hosts / * .conf;)不会更改目录? centos 7

I'm fairly new to Linux and I'm having a little trouble setting up my web server... I am using LEMP with Varnish and phpMyAdmin. The server is running and I can access phpMyAdmin over https etc. Now I'm trying to setup Wordpress on another directory using the include /directory/*.conf; however it doesn't seem to load the file(s). It will only load the default directory set in nginx.conf

Here's my nginx.conf,

user  nginx;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
worker_connections  1024;
}


http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile        on;

keepalive_timeout  65;

include       /etc/nginx/v-hosts/*.conf;

index   index.php index.html index.htm;

server {
    listen  127.0.0.1:8080;
    root         /usr/share/nginx/html;
    location / {
    }

    error_page  404              /404.html;
    location = /40x.html {
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }

location ~ \.php$ {
  root   /usr/share/nginx/html;
  fastcgi_split_path_info  ^(.+\.php)(.*)$;
  fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
  fastcgi_index  index.php;
  fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
  include fastcgi_params;
}
location ~* ^/stolenmx.com/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /srv/www/;
}

location ~ \.php$ {
  root   /usr/share/nginx/html;
  fastcgi_split_path_info  ^(.+\.php)(.*)$;
  fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
  fastcgi_index  index.php;
  fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
  include fastcgi_params;
}
}


server {
listen       443;
client_max_body_size 80M;    

ssl                  on;
ssl_certificate      /etc/nginx/ssl/server.crt;
ssl_certificate_key  /etc/nginx/ssl/server.key;

ssl_session_timeout  5m;

ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers   on;

location / {
root   /usr/share/nginx/html;
index  index.html index.htm;
}
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/;
}

location ~ \.php$ {
  root   /usr/share/nginx/html;
  fastcgi_split_path_info  ^(.+\.php)(.*)$;
  fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
  fastcgi_index  index.php;
  fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
  include fastcgi_params;
}
}
}

And here's my file i'm trying to load for wordpress,

server {
server_name stolenmx.com;
listen 8080;
access_log /var/log/nginx/stolenmx.com-access.log;
error_log /var/log/nginx/stolenmx.com-error.log;
root /srv/www/stolenmx.com;

location / {
    index index.php;
}

# Disable favicon.ico logging
location = /favicon.ico {
    log_not_found off;
    access_log off;
}

# Allow robots and disable logging
location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

# Enable permalink structures
if (!-e $request_filename) {
    rewrite . /index.php last;
}

# Handle php requests
location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /srv/www/stolenmx.com$fastcgi_script_name;
}

# Disable static content logging and set cache time to max
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
}

# Deny access to htaccess and htpasswd files
location ~ /\.ht {
    deny  all;
}
}

I have included this files directory in nginx.conf "include /etc/nginx/v-hosts/*.conf;" but for some reason it's not loading it and won't point the server_name to /srv/www/ ?

Does anyone have any suggestions as to why it won't load additional server.conf ?

I can drag the wordpress install into /usr/share/nginx/html and it works but then I can't have any more than one server. I think it's something to do with my nginx.conf but not sure what to change / add?

Regards Crafty

  • 写回答

1条回答 默认 最新

  • dongxia527680 2015-01-31 18:03
    关注

    Before changes can affect you need to restart/reload your nginx, in CentOS it's done by running:

    /etc/init.d/nginx restart
    

    (If you are not root use sudo)

    You are requiring that all your included files will be suffixed with '.conf', please make sure your file has this extension. Last thing, you configured your Wordpress server to listen on 8080, did you checked on this port?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了