我刚刚从 Apache 切换到 Nginx。
然后我被这个问题困住了。
当我使用 Apache 时,首先www(sub-domain)
可以通过这个自动删除.htaccess
如果我想要在 Nginx 上相同,我该怎么做?
这是我的旧.htaccess
.htaccess(我在使用 Apache 时正在使用它)
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(test-sample-site\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
然后这是我当前的confNginx
etc/nginx/conf.d/rails.conf
upstream sample {
ip_hash;
server unix:/var/run/unicorn/unicorn_sample.sock fail_timeout=0;
}
server {
listen 80;
server_name sample.jp;
root /var/www/html/sample/public;
location /wiki {
alias /usr/share/wiki;
index index.php;
}
location ~ ^/wiki.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^/wiki(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /usr/share/wiki$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://sample;
break;
}
}
location ~ ^/assets|system/ {
expires 1y;
add_header Cache-Control public;
log_not_found off;
}
}
更新
upstream sample {
ip_hash;
server unix:/var/run/unicorn/unicorn_sample.sock fail_timeout=0;
}
server {
listen 80;
server_name sample.jp;
root /var/www/html/sample/public;
location /wiki {
alias /usr/share/wiki;
index index.php;
}
location ~ ^/wiki.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^/wiki(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /usr/share/wiki$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://sample;
break;
}
}
location ~ ^/assets|system/ {
expires 1y;
add_header Cache-Control public;
log_not_found off;
}
}
server { # <== redirection server block
server_name www.sample.jp;
return 301 sample.jp$request_uri;
}