需要为 Amazon EC2 / Wordpress 配置 NGINX - 502 错误网关 / 403 禁止访问

需要为 Amazon EC2 / Wordpress 配置 NGINX - 502 错误网关 / 403 禁止访问

我已成功在 Amazon EC2 实例上安装了 wordpress。它运行正常,但 apache 服务不断减慢我的机器速度并导致实例过多。因此,我决定改用 NGINX。它已安装在我的服务器上。它已部分配置,但我无法使其完全运行。

当我直接访问任何文件夹时,我收到 403 禁止错误,当直接访问文件时,我收到 502 错误网关错误。你知道,我有 1 个弹性 IP 和多个指向该 IP 的域。

我需要的是每个域指向不同的子目录或“根”,其中第一个域指向最高级别的目录,即:

域 1 > /var/www 域 2 > /var/www/domain2.com 域 3 > /var/www/domain3.com

这是我的 nginx.conf 文件:

    # For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    index index.php index.html index.htm;

    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;
    tcp_nopush     on;
    tcp_nodelay        on;

    keepalive_timeout  10;

gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_comp_level 3; #You can vary this. 1 is least compression, 9 is most. I'll keep it low, since we have low CPU power.
gzip_buffers 16 8k;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

server {
    listen 80;
    server_name www.mysites.com;
    access_log /var/www/access.log;
    error_log /var/www/error.log;
    root /var/www/myfolder/mysites.com;

  # Pass PHP scripts to PHP-FPM
        location ~* \.php$ {
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }

}






}

答案1

如果您有不同的域,您可能应该有单独的服务器块。

server {
    listen 80;
    server_name domain1.com;
    access_log /var/www/access.domain1.log;
    error_log /var/www/error.domain1.log;
    root /var/www/domain1.com;
    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}
server {
    listen 80;
    server_name domain2.com;
    access_log /var/www/access.domain2.log;
    error_log /var/www/error.domain2.log;
    root /var/www/domain2.com;
    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}
server {
    listen 80;
    server_name domain3.com;
    access_log /var/www/access.domain3.log;
    error_log /var/www/error.domain3.log;
    root /var/www/domain3.com;
    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}

此外,除非必要,否则您不应将一个网站的内容嵌套在另一个网站中。最好将它们放在单独的目录中,以防您需要将一个网站移动到另一台服务器。

相关内容