A
A
AdvancedLAMER2018-05-08 11:47:40
Nginx
AdvancedLAMER, 2018-05-08 11:47:40

How to configure CNC on wordpress apache + nginx?

Good people, I ask for help
. I can’t think of anything to make the CNC work on wordpress on the apache + nginx bundle.
For the CNC to work, I added to the location:
proxy_pass http://127.0.0.1:81$request_uri;
try_files $uri $uri/ /index.php?$args;
But
nginx config doesn't help

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  
  server_name www.НАЗВАНИЕСАЙТА.ru НАЗВАНИЕСАЙТА.ru;

  return 301 http://$host$request_uri;
}
server {

  listen 80;
  listen [::]:80;
  root /var/www/НАЗВАНИЕСАЙТА/html;

  index index.php index.html index.htm;

  server_name www.НАЗВАНИЕСАЙТА.ru НАЗВАНИЕСАЙТА.ru;

  location / {
proxy_pass http://127.0.0.1:81$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
try_files $uri $uri/ /index.php?$args;
    }

  location ~ /\.ht {
    deny all;
    }

  location ~* \.(ico|docx|doc|xls|xlsx|rar|zip|jpg|jpeg|txt|pdf|gif|png|css|js|html)$ {
    root   /var/www/НАЗВАНИЕСАЙТА/html;
  }
  
  add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
  add_header Content-Security-Policy "block-all-mixed-content";
  add_header X-Frame-Options "SAMEORIGIN";
  add_header X-XSS-Protection "1; mode=block";
  add_header X-Content-Type-Options "nosniff";
  
  resolver 8.8.8.8;
}

Apache site config
<VirtualHost 127.0.0.1:81>
ServerName НАЗВАНИЕСАЙТА.ru 

ServerAlias www.НАЗВАНИЕСАЙТА.ru

ServerAdmin [email protected]НАЗВАНИЕСАЙТА.ru

DocumentRoot /var/www/НАЗВАНИЕСАЙТА/html

ErrorLog ${APACHE_LOG_DIR}/НАЗВАНИЕСАЙТА.ru_error.log

CustomLog ${APACHE_LOG_DIR}/НАЗВАНИЕСАЙТА.ru_access.log vhost_combined

ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php7.0-fpm.sock|fcgi://localhost/var/www/НАЗВАНИЕСАЙТА/html"

</VirtualHost>

Tell me who can

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Vorotnev, 2018-05-08
@HeadOnFire

1. Why do you need Apache? Use Nginx + PHP-FPM, then the CNC only needs one line in the Nginx config.
2. If you still need Apache, configure the CNC in .htaccess. Nginx in this bundle only forwards (proxies) requests to Apache, and their processing is performed by the latter.

G
German Zvonchuk, 2018-05-17
@inside22

As you have already been told above, give up Apache and you will be happy.
Here is the config and caching and many other useful things.
Here you will need to specify the correct version of your PHP.

server {
  
  listen 80;
  set $root_path '/home/wordpress/www'; # default directory where the files will be stored and served from
  root $root_path;
  
  index index.php; # index defined to be served under directory
  server_name www.blog.com;
      
  set $skip_cache 0;

  # POST requests and urls with a query string should always go to PHP
  if ($request_method = POST) {
    set $skip_cache 1;
  }   
  if ($query_string != "") {
    set $skip_cache 1;
  }   
  
  # Don't cache uris containing the following segments
  if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
    set $skip_cache 1;
  }
  
  # Don't use the cache for logged in users or recent commenters
  if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    set $skip_cache 1;
  }
  
  location ~* \.(gif|jpg|jpeg|png|ico|bmp|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|woff|woff2|exe|eot|svg|ttf)$ {
    root $root_path;
    expires 14d;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    access_log off;
    log_not_found off;
  }
  
  #    Common deny or internal locations, to help prevent access to areas of
  #    the site that should not be public
  location ~* wp-admin/includes { deny all; }
  location ~* wp-includes/theme-compat/ { deny all; }
  location ~* wp-includes/js/tinymce/langs/.*\.php { deny all; }
  location /wp-content/ { internal; }
  location /wp-includes/ { internal; }
  
  #    The next line protects the wp-config.php file from being accessed, but
  #    we need to be able to run the file for the initial site setup. Uncomment
  #    the next line after setup is completed and reload Nginx.
  location ~* wp-config.php { deny all; }

  #    Prevent any potentially-executable files in the uploads directory from
  #    being executed by forcing their MIME type to text/plain
  location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
    types { }
    default_type text/plain;
  }

  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  error_page 404 /404.html;

  error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/www;
  }

  location ~ \.php$ {
    try_files $uri =404;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;

    fastcgi_split_path_info       ^(.+\.php)(/.+)$;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_read_timeout    3600;

    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;

    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid  5m;
  }
}

/etc/nginx/nginx.conf
##
# Fastcgi Params
##
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

S
seregylive, 2019-04-05
@seregylive

So I didn’t understand where to write. I only have this on my VPS
;#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
error_log /usr/local/apps/nginx/var/log/error_log debug;
http {
include 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 /usr/local/apps/nginx/var/log/web.access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
client_max_body_size 200M;
# If your domain names are long, increase this parameter.
server_names_hash_bucket_size 64;
# To hide the version number in headers
server_tokens off;
include /usr/local/apps/nginx/etc/conf.d/*.conf;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question