我试图在我的wordpress安装上激活相当永久链接,但没有成功。我正在更改此文件/etc/nginx/conf.d/default.conf
我尝试了以下内容:
server{
if (!-e $request_filename) { rewrite ^.*$ /index.php last;
server {
if ($host ~* ^myhost\.com$) {
rewrite ^(.*) http://www.myhost.com$1 permanent;
break;
}
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
但这些都不起作用:(。这是我的完整档案:
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
listen 80;
server_name www.example.com;
note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
你能帮我吗?
非常感谢。
答案 0 :(得分:1)
server {
listen 80;
server_name your-domain.com www.your-domain.com;
root /usr/share/nginx/html/your-wp-root-dir;
index index.php index.html index.htm;
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;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
更新nginx
文件(default.conf
)
sudo /etc/init.d/nginx restart
服务器
答案 1 :(得分:0)
有点晚了,
试
location / {
try_files $uri $uri/ /index.php?q=$uri$args;
}