I'm converting this htaccess file htaccess file
to nginx using
http://winginx.com/ru/htaccess
but don't understand where i should paste result. I have created
include file
include /etc/nginx/myfile
and pasted file there but when i'm reloading (restarting) Nginx it Fails.
Could you help me?
I suspect these apache .htaccess converters do not fully utilize the unique features of nginx. I would recommend trying something like this:
server {
listen 80 default_server;
server_name _;
root /var/www/example.com;
index index.php;
# if the file or directory doesn't exist, serve /index.php
try_files $uri $uri/ /index.php;
# if the request is exactly /sitemax.xml, serve sitemap_xml.php
location = /sitemax.xml {
try_files /modules/sitemap/sitemap_xml.php =404;
}
# hide regex location in a prefix location to avoid confusion
# introduced by multiple regex locations
location /pages-print {
location ~ ^/pages-print(\d+) {
try_files /modules/pages/print.php?page=$1 =404;
}
}
}
I have found solution. I tried paste result from the convertor to nginx.conf and it was mistake. I, instead created file in /etc/nginx/ and named it htac.rules (i think it doesn't matter of how you'll name it).
Then i opened file etc/nginx/sites-enabled/default and in location / inserted include /etc/nginx/htac.rules
so.
in htac.rules i inserted converting result without location / {...}
and, yeah. It solved my problem.
Thanks everyone for helping me.
Related
I have this hierarchy on my server:
/var/www/domain.tld/web
/sub
The root in the /etc/nginx/sites-available/domain.tld is set like this:
server {
root /var/www/domain.tld/web;
index index.html index.php index.htm;
...
location / {
try_files $uri $uri/ =404;
}
How can I make the nginx to dynamically forward to specific folder so if I make folder in /sub for example /var/www/domain.tld/sub/subdomain so if I make request http://subdomain.domain.tld it will forward to this folder in folder sub?
So again something.domain.tld would be going to /var/www/domain.tld/sub/something but domain.tld would be going to /var/www/domain.tld/web
Thank you!
First off, welcome to StackOverflow! :)
There are probably a few ways of achieving this, but I would try a simple map to set a $my_subdir variable from the $host, which you can then use in your root. The $host variable is set automatically from the incoming request.
In this example, we're using a regular expression to check if the $host matches subdomain.domain.tld. If it does, capture the subdomain part - the bit in brackets - and use that to make the value "sub/subdomain" ($1 means use the first thing captured from the regular expression). If it doesn't match, it defaults to "web".
That way,
when the request comes in as something like http://domain.tld/foo.html, the response served is /var/www/domain.tld/web/foo.html
if the request comes in as something like http://bar.domain.tld/foo.html, the response served is /var/www/domain.tld/sub/bar/foo.html
map $host $my_subdir {
~^(?:www\.)?((?!www\.)[^.]+)\.domain\.tld$ sub/$1;
default web;
}
server {
root /var/www/domain.tld/$my_subdir;
index index.html index.php index.htm;
...
location / {
try_files $uri $uri/ =404;
}
I want to redirect all my media files to maxcdn origin poll, this might be duplicate question
but couldn't find the way i was looking for.
example:
If visitor request something like : http://domain.com/monday/day1.mp3 it needs to redirect to http://xxx.netdna.com/monday/day1.mp3.
Question: --- No To This :/
Will nginx allow .htaccess to do this job?
Or
Do I need to setup server config? How
Here is my config, which is every simple.
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /var/www/domain/public_html;
index index.html index.php index.htm;
# Make site accessible from http://localhost/
server_name domain.com;
return 301 http://XXX.YYYY.netdna-cdn.com$request_uri;
The page isn't redirecting properly
Please Help!
Will nginx allow .htaccess to do this job?
No. There is no .htaccess analogue for nginx.
This will redirect all request to folder /podcast/ to xxx.netdna.com.
location /podcast/ {
return 301 http://xxx.netdna.com$request_uri;
}
I have found solution for my problem after a huge dig search on google, but the answer was so simple, didn't realized till it turned on working perfectly for my problem... :)
All I need to add was, following code right after location /
Here is what i added and worked like charm.
try_files $uri $uri/ /index.php;
I have followed this website http://raspberrypihelp.net/tutorials/24-raspberry-pi-webserver to setup the HTTP server nginx on my Raspberry Pi and try to setup a site call example.com. But when I run sudo service nginx restart, it said
Restarting nginx: nginx: [emerg] unknown directive " " in /etc/nginx/sites-enabled/example.com:3
Here is the code in example.com.
server {
server_name example.com 192.168.1.88;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
root /srv/www/example.com/public/;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public$fastcgi_script_name;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
I am just following the steps but it can't run successfully.
I had the same problem which was that I copy/pasted the config code from the web and some dirty EOL(end of line) characters where there.
The editor didn't show them, but nginx treated them like a directive.
Just deleted every EOL and added again.
It sounds like you did some copy and paste work here. It's not uncommon to snag some extra characters that are invisible at the end of line (EOL). Try this:
Run your text through this tool:
http://www.textfixer.com/tools/remove-line-breaks.php
then fix any breaks that may have been removed and will be affected by the comments.
This worked for me. Hope it works for you.
It looks like the nginx binary was compiled with --without-http_fastcgi_module option.This is not default. Try donwloading or compiling a different binary.
Try running
nginx -V
(with uppercase V) to see what options were used to compile the nginx.
I edited some text in the mid of the conf file and nginx started showing this error at the starting of the file itself. I copied the contents of the file, created a new file, pasted the contents there and nginx stopped showing this error.
I faced similar issue with error message as "unknown directive 'index.html'" when running 'sudo nginx -t'. After correcting the HTML syntax errors in index.html, the issue was resolved.
Even if you miss a semicolon you will encounter the same error.
// Missed semicolon
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock
// With semicolon
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
In my case, I have store configuration file nginx.conf in the github. I have done wget to raw version of code, thus resulted this error.
Later, I have cloned my repository and used the nginx.conf file from clone and issue got resolved.
Really didn't got how that happened,
I've "docker run " my nginx 1.14 (default apt for debian:bullseye) to extract it's default nginx.conf, with intention to update it and than use it into my Dockerfile.
Anyhow, after having read comments in this thread, found this that the file is
"UTF-16LE" ... I'm not really expert, but is not "UTF-8".
solved as:
Issue seen from inside the container:
me#docker-nginx $ head nginx.conf
��
user www-data:qgis;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
error_log /dev/stdout warn;
events {
worker_connections 768;
me#docker-nginx $ dos2unix nginx.conf
dos2unix: converting UTF-16LE file nginx.conf to UTF-8 Unix format...
Solved also on working dir:
IntelliJ IDEA: select "convert" after "UTF-8"
I had the same problem when I looked inside my config file there was a syntax error so this might be the problem check this path
nano /etc/nginx/sites-available/example.com
I need help to converting this .htaccess to Nginx. Here is the .htaccess code:
RewriteRule wp-content/thesis/skins/(.*)/css.css wp-admin/admin-post.php?action=thesis_do_css
I already convert those rules to online nginx converter. So far I get this code:
rewrite /wp-content/thesis/skins/(.*)/css.css /wp-admin/admin-post.php?action=thesis_do_css;
I put those code above under try_files rules. Here is the complete code:
location / {
try_files $uri $uri/ /index.php?q=$uri$is_args&$args;
rewrite /wp-content/thesis/skins/(.*)/css.css /wp-admin/admin-post.php?action=thesis_do_css;
}
So, it doesn't work. Please help me understanding about nginx rules. Thanks.
Beny
try_files is final. You cannot put anything after it and expect it to be evaluated. Think of try files as an if-then-else statement, where the last part is always the else. Since there are probably a lot more rules involved, you are best off consulting the WordPress codex.
If you need just to rewrite that one css.css file to wp-admin/admin-post.php?action=thesis_do_css then try this:
if ($request_filename ~ wp-content/thesis/skins/classic-r/css.css ) {
rewrite ^ http://mydomain.com/wp-admin/admin-post.php?action=thesis_do_css? permanent;
}
That should be within your server{ block. Make sure to change mydomain.com to your actual domain, of course.
I hope that helps.
my host server is nginx.
in the root directory i have installed magento, then i created a file named blog, then installed wordpress into it.
now, the directory is:
app
includes
....
blog/wp-admin
when i set http://www.example.com/blog/index.php/%postname%.html in Permalink Settings. access all the post, it's ok. now i want to remove the index.php. namely change it into http://www.example.com/blog/%postname%.html.when i delete the index.php. all the post are not unavailable,
EDIT:
i put the code in the nginx.conf.
location /blog/ {
index index.php;
try_files $uri $uri/ /blog/index.php?$uri&$args;
rewrite ^ /index.php? last;
}
but it doesn't work. is there something i lost?