Help Rewrite URL trên nginx

nguyenchican

Private
Tham gia
09/10/2015
Bài viết
8
Được Like
6
Chào anh em, mình setup xenForo trên nginx, nhưng vướng lại ở chổ rewrite url, do nginx ko đọc đc .htaccess.
Mình đã thử covert htaccess và rule nginx nhưng ko thể restart đc Apache, lỗi như sau:
"
root@nhaccong:~# service nginx restart
* Restarting nginx nginx [fail]
"
kiểm tra em bằng lệnh nginx -t thì báo như sau:

"
root@nhaccong:~# nginx -t
nginx: [emerg] open() "/usr/local/nginx/conf/staticfiles.conf" failed (2: No suc h file or directory) in /etc/nginx/conf.d/nhaccong.net.conf:42
nginx: configuration file /etc/nginx/nginx.conf test failed
"
File Nginx.conf
"
root@nhaccong:~# cat /etc/nginx/nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

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_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript t ext/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}

"
File etc/nginx/conf.d/nhaccong.net.conf

"
root@nhaccong:~# # }
root@nhaccong:~# #}
root@nhaccong:~# cat /etc/nginx/conf.d/nhaccong.net.conf
# redirect from non-www to www
# uncomment, save file and restart Nginx to enable
#server {
# listen 80;
# server_name nhaccong.net;
# return 301 $scheme://www.nhaccong.net$request_uri;
# }

server {
server_name nhaccong.net www.nhaccong.net;

# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;

# limit_conn limit_per_ip 16;
# ssi on;

access_log /home/nginx/domains/nhaccong.net/log/access.log combined buffer=32k;
error_log /home/nginx/domains/nhaccong.net/log/error.log;

root /home/nginx/domains/nhaccong.net/public;

location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$uri&$args;
}

location /internal_data/ {
internal;
allow 127.0.0.1;
deny all;
}

location /library/ {
internal;
allow 127.0.0.1;
deny all;
}

include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
}root@nhaccong:~#

"
Server mình chạy Lemp Ubuntu ở Digital Ocean.
Anh em có thời gian thì teamview hổ trợ giúp mình với nhé.
Online: nhaccong.net
 
  • Like
Reactions: THB

nguyenchican

Private
Tham gia
09/10/2015
Bài viết
8
Được Like
6
Vẫn không restart đc Nginx, đoạn code bên trang bạn đưa mình cho vào cuối file Nginx.conf

root@nhaccong:~# nginx -t
nginx: [emerg] "location" directive is not allowed here in /etc/nginx/nginx.conf:99
nginx: configuration file /etc/nginx/nginx.conf test failed
root@nhaccong:~#
 

Đính kèm

  • nginx.zip
    1 KB · Lượt xem: 7
  • Like
Reactions: THB

Hướng dẫn sử dụng

XenForo 1 XenForo 2
Translate by PVS

Dịch vụ XenForo của VNXF

Mobile/Zalo: 0906081284

Telegram: anhanhxf

Chỉ nhận web nội dung lành mạnh

Nhà Tài Trợ

Mút Xốp Không Gian
Mút Sofa Không Gian
Top Bottom