I am quite new to Nginx and I just can't make it work. I have a web app hosted in Azure. It's a WordPress website.
Here is the Nginx file:
server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot;
index index.php;
server_name my-app.azurewebsites.net;
port_in_redirect off;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
sendfile off;
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;
}
# Don't cache WooCommerce URLs
# Cart widgets are still a problem: https://github.com/emcniece/docker-wordpress/issues/3
if ($request_uri ~* "/(cart|checkout|my-account)/*$") {
set $skip_cache 1;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /html/;
}
# Disable .git directory
location ~ /\.git {
deny all;
access_log off;
log_not_found off;
}
# Add locations of phpmyadmin here.
# location ~ [^/]\.php(/|$) {
location ~ \.php$ {
# fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass php;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
# fastcgi_connect_timeout 300;
# fastcgi_send_timeout 3600;
# fastcgi_read_timeout 3600;
# fastcgi_buffer_size 128k;
# fastcgi_buffers 4 256k;
# fastcgi_busy_buffers_size 256k;
# fastcgi_temp_file_write_size 256k;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache off;
fastcgi_cache_valid 60m;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
add_header "Access-Control-Allow-Origin" *;
}
server {
listen 80;
server_name my-app.azurewebsites.net;
return 301 https://$host$request_uri;
}
My first issue is related to the headers. I tried to add some headers but they are completely ignored. I searched through the parent block, hoping to find something that is overwriting it, in the main Nginx folder, but haven't found anything related to headers.
Another issue is related to /wp-admin folder which I can't access. It enters in some loop with response code 302.
I don't know why but some resources are loaded via http and some others via https.
Any suggestions would much appreciated.
Thanks in advance, Ciprian