I have an issue with a Wordpress installation on a subdomain and seems to be redirecting to the root website. When first accessing the subdomain (blog.example.com), it works fine but the second time, it seems to redirect to the root URL (example.com).
Here is the Nginx code:
server {
listen 80;
#listen [::]:80 default_server ipv6only=on;
root /var/www/html/blog-au;
index index.php index.html index.htm;
server_name blog.example.com;
location / {
# try_files $uri $uri/ =404;
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/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Please do let me know if you need anymore information from me.
Thanks in advance.
Related
I am pretty new to NGINX and have a background with Apache. My company is deploying a server that hosts multiple websites. Specifically libretime in one webroot, and our corporate website in the default webroot.
I am having a heck of a time trying to configure the subdomain. I have ruled out cloudflare and I have the DNS set correctly but it just wont go.
I have created two configs in sites-available and simlinked them. Each going to the respective webroot. I also have configured both the main domain and subdomain with SSL.
Whenever I try and go to the subdomain "https://radio.example.com" it gets redirected to "https://example.com" and never allows me to go to the subdomain.
Please see the below config files, any help would be appreciated as im getting conflicting info.
server {
listen 443 ssl default_server;
listen 80 default_server;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/certs/example.com.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;
server_name www.example.com example.com;
server_name_in_redirect on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /var/www/html/example.com;
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
index index.php index.html index.htm;
client_max_body_size 512M;
client_body_timeout 300s;
location ~ \.php$ {
fastcgi_buffers 64 4K;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# try_files $uri =404;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
}
Second Subdomain
server {
listen 80;
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/certs/example.com.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;
server_name radio.example.com;
return 301 $scheme://radio.example.com$request_uri;
server_name_in_redirect on;
access_log /var/log/nginx/libretime.access.log;
error_log /var/log/nginx/libretime.error.log;
root /usr/share/libretime/legacy/public;
index index.php index.html index.htm;
client_max_body_size 512M;
client_body_timeout 300s;
location ~ \.php$ {
fastcgi_buffers 64 4K;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# try_files $uri =404;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/run/libretime-legacy.sock;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ ^/api/(v2|browser) {
include proxy_params;
proxy_redirect off;
proxy_pass http://unix:/run/libretime-api.sock;
}
}
Thanks!
How do I convert the following Nginx rule into .htaccess?
location ~* \.(jpg|jpeg|gif|png)$ { try_files $uri/ /image-proxy.php$is_args$args; }
My server is running LEMP on Debian Jessie.
I am trying to force "www." to occur. I was able to do this with the following solution found on Stackoverflow.
return 301 http://www.example.com$request_uri;
However, I am running several websites from the server and the issue I am running into is as follows.
When logging into wordpress www.site1.com/wp-admin on one website, it routes me to www.site0.com/wp-admin. I believe this issue has to do with a default_server or hostname issue. Do I need to add all hostnames to /etc/hostname ?
Here is my host file
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
root /var/www/site0;
index index.php index.html index.htm;
server_name site0.com;
#return 301 http://www.site0.com$request_uri;
location / {
try_files $uri $uri/ =404;
#try_files $uri $uri/ /index.html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 80;
listen [::]:80;
# SSL configuration
#listen 443 ssl;
#listen [::]:443 ssl;
root /var/www/site1;
index index.php index.html index.htm;
server_name site1.com;
#return 301 http://www.site1.com$request_uri;
location / {
try_files $uri $uri/ =404;
#try_files $uri $uri/ /index.html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
I am thinking part of the issue has to do with:
listen 80 default_server;
listen [::]:80 default_server;
Please help if you can, it will be very much appreciate.
I found a very comprehensive guide here: https://www.digitalocean.com/community/tutorials/how-to-configure-single-and-multiple-wordpress-site-settings-with-nginx
The part you might find relevent is this:
# Rewrite rules for WordPress Multi-site.
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
Seems to be rewriting wordpress requests, specifically /wp-admin to the correct domain.
I want to redirect my domain example.com to www.example.com
My /etc/nginx/sites-available/example.com configuration is
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
What changes should I do in this code?
I have added this line :
try_files $uri $uri/ /index.php?q=$request_uri;
for wordpress permanent link correction.
You need a separate server block to listen for the non www and 301 it to www like this
server {
listen 80;
server_name netmark.com;
return 301 $scheme://www.netmark.com$request_uri;
}
You can read this tutorial to move a domain to another domain but from what I understand you only want to change the actual domain prefix.
Hello I am trying to covert the following .htaccess lines so that arrowchat can work in my nginx server. The location of my arrowchat folder is like this /usr/share/nginx/html/arrowchat/ where /usr/share/nginx/html/ is the root folder for my website. My VPS has only one website, www.jukpac.com hosted on it. Below is the .htaccess code
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^chatroom ^/../public/chatroom/ [L]
RewriteRule ^cron ^/../public/cron/ [L]
RewriteRule ^debug ^/../public/debug/ [L]
RewriteRule ^list ^/../public/list/ [L]
RewriteRule ^mobile ^/../public/mobile/ [L]
RewriteRule ^popout ^/../public/popout/ [L]
RewriteRule ^video ^/../public/video/ [L]
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(gif|jpg|png|css|swf)$">
Header add "Expires" "Mon, 28 Jul 2014 23:30:00 GMT"
Header add "Cache-Control" "max-age=31536000"
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType application/x-shockwave-flash A604800
</IfModule>
I tried a few online .htaccess converter but it didn't work can some one please let me know how to fix this?
My current default.conf file for nginx looks like this
#
# The default server
#
server {
listen 80;
server_name jukpac.com;
return 301 http://www.jukpac.com$request_uri;
}
server {
listen 80;
server_name www.jukpac.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Ok with the Help of a friend, in Serverfault I managed to get the correct configuration as shown below
server { #redirecting server
listen 80;
server_name jukpac.com;
return 301 http://www.jukpac.com$request_uri;
}
server {
listen 80;
server_name www.jukpac.com;
root /usr/share/nginx/html; #move the root to server level
index index.php # move index to server level
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ =404;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png|swf)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}