1、nginx怎麼配置IP和域名都能訪問
一個nginx伺服器只能有一個虛擬主機允許IP訪問
只要在server_name最後面添加一個default,就可以在其他nginx沒有定義的域名下,使用當前server解析(例如,其他server都沒有定義ip地址作為server_name則用IP訪問會被打到default主機上)
2、nginx配置域名問題
證書風險就肯定是你的證書有問題,你買的泛域名的還是單個域名的證書?你可以查看一下具體的錯誤:
3、nginx 配置域名訪問
這個是有配置上的問題啊 , 最好能遠程幫你看看, 能看下窩的網名嗎, 可以私聊搞定的啊
4、nginx配置域名後,不能載入css,ip訪問沒問題,只有jenkins不能訪問
這個問題的原因應該來說比較多
1、是否配置正確 server_name
2、DNS域名解析是否正確,可以回ping一下你的域名
3、是否需答要做url重寫或者url重寫是否配置正確
4、是否需要單獨對於css js及圖片這些單獨指定目錄
5、檢查css js文件請求的地址是否正確以及伺服器目錄中是否有相應的文件
5、如何設置 NGINX,使根域名不可訪問,但是其他非根路徑可以訪問
location 沒有那個比較符的,可以這樣
```
location ~* /.+ {
# do something...
}
```
6、如何配置nginx達到只允許域名訪問網址,禁止ip
Nginx 禁止IP訪問
我們在使用的時候會遇到很多的惡意IP攻擊,這個時候就要用到Nginx 禁止IP訪問了。下面我們就先看看Nginx的默認虛擬主機在用戶通過IP訪問,或者通過未設置的域名訪問(比如有人把他自己的域名指向了你的ip)的時候生效最關鍵的一點是,在server的設置裡面添加這一行:
listen 80 default;
後面的default參數表示這個是默認虛擬主機。
Nginx 禁止IP訪問這個設置非常有用。
比如別人通過ip或者未知域名訪問你的網站的時候,你希望禁止顯示任何有效內容,可以給他返回500.目前國內很多機房都要求網站主關閉空主機頭,防止未備案的域名指向過來造成麻煩。就可以這樣設置:
server {
listen 80 default;
return 500;
}
7、求助Nginx設置後只能訪問IP,無法通過域名訪問
你的域名是否解析到了伺服器,域名是否有備案,這兩點沒做的話是不能通過域名訪問的。
8、Nginx伺服器不能用瀏覽器訪問域名怎麼辦
默認location里得加index指令吧,不然你只有域名沒指明具體的資源名當然就404了。
9、nginx 配置域名之後怎麼解決
方法一:多個.conf方法(優點是靈活,缺點就是站點比較多配置起來麻煩)
這里以配置2個站點(2個域名)為例,n 個站點可以相應增加調整,假設:
IP地址: 192.168.1.100
域名1 example1.com 放在 /www/example1
域名2 example2.com 放在 /www/example2
配置 nginx virtual hosting 的基本思路和步驟如下:
把2個站點 example1.com, example2.com 放到 nginx 可以訪問的目錄 /www/
給每個站點分別創建一個 nginx 配置文件 example1.com.conf,example2.com.conf, 並把配置文件放到 /usr/local/nginx/vhosts/
然後在 /usr/local/nginx/nginx.conf 裡面加一句 include 把步驟2創建的配置文件全部包含進來(用 * 號)
重啟 nginx
1、打開 /usr/local/nginx/nginix.conf 文件,在相應位置加入 include 把以上2個文件包含進來
user www www;
worker_processes 1;
# main server error log
error_log /usr/local/nginx/log/nginx/error.log ;
pid /usr/local/nginx/nginx.pid;
events {
worker_connections 51200;
}
# main server config
http {
include mime.types;
default_type application/octet-stream;
log_format main 『$remote_addr – $remote_user [$time_local] $request 『
『」$status」 $body_bytes_sent 「$http_referer」 『
『」$http_user_agent」 「$http_x_forwarded_for」『;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
access_log /usr/local/nginx/log/nginx/access.log main;
server_name_in_redirect off;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
# 包含所有的虛擬主機的配置文件
include /usr/local/nginx/vhosts/*;
}
2、在 /usr/local/nginx 下創建 vhosts 目錄
mkdir /usr/local/nginx/vhosts
3、在 /usr/local/nginx/vhosts/ 里創建一個名字為 example1.com.conf 的文件,把以下內容拷進去
server {
listen 80;
server_name example1.com www. example1.com;
access_log /www/access_ example1.log main;
location / {
root /www/example1.com;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/example1.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
3、在 /usr/local/nginx/vhosts/ 里創建一個名字為 example2.com.conf 的文件,把以下內容拷進去
server {
listen 80;
server_name example2.com www. example2.com;
access_log /www/access_ example1.log main;
location / {
root /www/example2.com;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/example2.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
5、重啟 Nginx
/etc/init.d/nginx restart
方法二:動態目錄方法(優點是方便,每個域名對應一個文件夾,缺點是不靈活)
這個簡單的方法比起為每一個域名建立一個 vhost.conf 配置文件來講,只需要在現有的配置文件中增加如下內容:
# Replace this port with the right one for your requirements
# 根據你的需求改變此埠
listen 80; #could also be 1.2.3.4:80 也可以是1.2.3.4:80的形式
# Multiple hostnames seperated by spaces. Replace these as well.
# 多個主機名可以用空格隔開,當然這個信息也是需要按照你的需求而改變的。
server_name star.yourdomain.com *.yourdomain.com http://www.*.yourdomain.com/;
#Alternately: _ *
#或者可以使用:_ * (具體內容參見本維基其他頁面)
root /PATH/TO/WEBROOT/$host;
error_page 404 http://yourdomain.com/errors/404.html;
access_log logs/star.yourdomain.com.access.log;
location / {
root /PATH/TO/WEBROOT/$host/;
index index.php;
}
# serve static files directly
# 直接支持靜態文件 (從配置上看來不是直接支持啊)
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires 30d;
}
location ~ .php$ {
# By all means use a different server for the fcgi processes if you need to
# 如果需要,你可以為不同的FCGI進程設置不同的服務信息
fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /PATH/TO/WEBROOT/$host/$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
}
location ~ /.ht {
deny all;
}
最後附另外一個二級域名匹配的方法
綁定域名
server_name *.abcd.com;
獲取主機名
if ( $host ~* (.*).(.*).(.*))
{
set $domain $1;
}
定義目錄
root html/abc/$domain/;
location /
{
root html/abcd/$domain;
index index.html index.php;
10、如何配置nginx 只能通過域名訪問
為了避免別人把未備案的域名解析到自己的伺服器ip而導致伺服器被斷回網,需要在nginx上設置答禁止通過ip訪問伺服器,只能通過域名訪問。
最關鍵的一點是,在server的設置裡面添加這么一行:
Listen 80 default;
後面的default參數表示這個是默認的虛擬主機。
例如:別人如果通過ip或者未知域名訪問你的網站的時候,你希望禁止顯示任何有效內容,可以給他返回500。具體如下:
Server {
Listen 80 default;
Server_name _;
Return 500;
}
當然,按照上述設置,的確不能讓別人通過ip訪問伺服器了,但是還應該開放一個或多個真實的希望被訪問的域名配置,設置如下:
Server {
Linten 80;
Server_name ; (以3A網路為例)
………..
}