Portal Home > Knowledgebase > Articles Database > Nginx redirect one file to another website
Nginx redirect one file to another website
Posted by aniga17, 03-31-2016, 11:15 AM |
Hello,
How to redirect xmlrpc.php to http://0.0.0.0.com in Nginx
I used this code
server {
listen 192.168.1.100:80;
server_name mydomain.com;
return 301 http://anotherdomain.com/dir1/index.php;
}
When i click restart nginx.conf i got this error
Restarting Nginx...
Something went wrong, check the Nginx log.
Please help
|
Posted by itsyndicateorg, 03-31-2016, 11:46 AM |
Provide the log here, please
|
Posted by aniga17, 03-31-2016, 11:49 AM |
Which logs? also provide me the command line to get that logs
|
Posted by itsyndicateorg, 03-31-2016, 11:58 AM |
log files are usually located /var/log/nginx
Last edited by itsyndicateorg; 03-31-2016 at 12:09 PM.
|
Posted by Srv24x7, 03-31-2016, 12:05 PM |
Hi,
Try the below link and see if you get the apache one converted to Nginx and then try the same in the Nginx and see if it works for you..
http://winginx.com/en/htaccess
|
Posted by itsyndicateorg, 03-31-2016, 12:07 PM |
Please type nginx -t in your console ans paste output here.
|
Posted by aniga17, 03-31-2016, 12:11 PM |
Thank you very much
this is the code from htaccess to nginx
# nginx configuration
location ~ ^/xmlrpc.php {
rewrite ^(.*)$ http://www.0.0.0.0.com redirect;
}
but i am getting same error
Restarting Nginx...
Something went wrong, check the Nginx log.
|
Posted by aniga17, 03-31-2016, 12:12 PM |
here is the log
2016/03/31 19:07:47 [emerg] 85304#0: "location" directive is not allowed here in /etc/nginx/nginx.conf:94
i have this code in nginx
# nginx configuration
location ~ ^/xmlrpc.php {
rewrite ^(.*)$ http://www.0.0.0.0.com redirect;
}
|
Posted by itsyndicateorg, 03-31-2016, 12:21 PM |
aniga17, it would be great if you attach your full config to this post or send me a PM with your /etc/nginx/nginx.conf
You have an error in your config and due to this you are not able to restart NginX.
|
Posted by aniga17, 03-31-2016, 12:53 PM |
user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;
pid /var/run/nginx.pid;
events {
worker_connections 8192;
multi_accept on;
use epoll;
}
http {
## Basic Settings ##
client_body_timeout 5s;
client_header_timeout 5s;
client_max_body_size 1024m;
keepalive_timeout 20s;
port_in_redirect off;
sendfile on;
server_names_hash_bucket_size 64;
server_name_in_redirect off;
server_tokens off;
tcp_nodelay on;
tcp_nopush on;
types_hash_max_size 2048;
# DNS Resolver
# If in China, enable the OpenDNS entry that matches your network connectivity (IPv4 only or IPv4 & IPv6)
# OpenDNS (IPv4 & IPv6)
#resolver 208.67.222.222 208.67.220.220 2620:0:ccc::2 2620:0:ccd::2;
# OpenDNS (IPv4 only)
#resolver 208.67.222.222 208.67.220.220;
# Google Public DNS (IPv4 & IPv6)
#resolver 8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844;
# Google Public DNS (IPv4 only) [default]
resolver 8.8.8.8 8.8.4.4;
## MIME ##
include /etc/nginx/mime.types;
default_type application/octet-stream;
## Logging Settings ##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
## Gzip Settings ##
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 5;
gzip_disable "msie6";
gzip_min_length 256;
gzip_proxied any;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-javascript
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/javascript
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy
text/x-js
text/xml;
gzip_vary on;
# Proxy Settings
proxy_cache_path /tmp/engintron_dynamic levels=1:2 keys_zone=engintron_dynamic:20m inactive=10m max_size=500m;
proxy_cache_path /tmp/engintron_static levels=1:2 keys_zone=engintron_static:20m inactive=10m max_size=500m;
proxy_temp_path /tmp/engintron_temp;
## Virtual Host Configs ##
include /etc/nginx/conf.d/*.conf;
}
# nginx configuration
location ~ ^/xmlrpc.php {
rewrite ^(.*)$ http://www.0.0.0.0.com redirect;
}
|
Posted by itsyndicateorg, 03-31-2016, 01:02 PM |
1. Please remove following:
After that you should change desired domain's config file in the /etc/nginx/conf.d/ folder and add following to the server section:
location /xmlrpc.php {
return 301 http://anotherdomain.com/dir1/index.php;
}
This will redirect all requests for /xmlrpc.php to http://anotherdomain.com/dir1/index.php , but without params.
Please be advised that location is available only in server or location block.
|
Posted by aniga17, 03-31-2016, 03:42 PM |
what do i do with /etc/nginc/conf.d folder ?
Do i have to create /ect/nginx/conf.d?
Please guide me and tell me the steps one by one
You are hero
|
Posted by aniga17, 04-03-2016, 10:37 AM |
Is there any one can help me with this issue
|
Posted by aniga17, 04-03-2016, 11:28 AM |
I have resolved this issue thanks for your support
|
Posted by itsyndicateorg, 04-03-2016, 02:18 PM |
aniga17, it would be great if you share solution that helped you with NginX redirect and xmlrpc issue. So others will be able to use that in the future.
|
Add to Favourites Print this Article
Also Read