I am trying to setup my windows development machine with nginx and I would like to be able to run multiple sites. What I tried to do is assign different ip addresses for each domain in nginx.conf and hosts files as below:
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
gzip on;
server_tokens off;
add_header X-Frame-Options Deny;
expires 365d;
include mime.types;
server {
listen 172.76.0.10:80;
server_name mywebsite.local;
root /Websites/mywebsite_dev;
location / {
index index.php;
}
location ~ \.php {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
server {
listen 172.76.0.11:80;
server_name mywebsite-two.local;
root /Websites/mywebsite-two_dev;
location / {
index index.php;
}
location ~ \.php {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
}
hosts
172.76.0.10 mywebsite.local
172.76.0.11 mywebsite-two.local
But when I try to run the nginx service I get this error:
nginx: [emerg] bind() to 172.76.0.10:80 failed (10049: FormatMessage() error:(15100))
Anyone has an idea on what I'm doing wrong?
Related
my website work with hsts http redirection https working but when i want use www i have 502 nginx in brower
I have alias in panel www.mydomain.com
and my log error when i type nginx -t
nginx: [warn] conflicting server name "mydomain.com" on MYIP:80, ignored
nginx: [warn] conflicting server name "www.mydomain.com" on 0.0.0.0:80, ignored
Nginx.conf
server {
listen 80;
server_name www.mydomain.com;
}
server {
listen myIP:80;
server_name mydomain.com;
root /home/razor/web/mydomain.com/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/mydomain.com.log combined;
access_log /var/log/nginx/domains/mydomain.com.bytes bytes;
error_log /var/log/nginx/domains/mydomain.com.error.log error;
include /home/razor/conf/web/mydomain.com/nginx.forcessl.conf*;
location / {
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
fastcgi_hide_header "Set-Cookie";
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/run/php/php7.4-fpm-mydomain.com.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
location /error/ {
alias /home/razor/web/mydomain.com/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias /home/razor/web/mydomain.com/stats/;
include /home/razor/web/mydomain.com/stats/auth.conf*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /home/razor/conf/web/mydomain.com/nginx.conf_*;
}
nginx.hsts.conf
client_max_body_size 5G;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
fastcgi_pass unix:/run/php/php8.0-fpm-php8.fhscript.com.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
include /etc/nginx/fastcgi_params;
}
#location / {
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?_page_url=$1 last;
}
#}
location /files/ {
internal;
}
# these locations would be hidden by .htaccess normally
location /logs/ {
deny all;
}
NGINX processed the configuration file line by line or for the order of files in alphabetical order.
What is happening here is you have provided 2 blocks to NGINX that are listening on port 80.
Just remove this part and you should be good to go.
server {
listen 80;
server_name www.mydomain.com;
}
I changed the configuration of nginx, and then restarted nginx when the following error occurs.
[root#host ~]# nginx -s reload
nginx: [emerg] unknown directive "server" in /usr/local/openresty/nginx/conf/vhost/www.xxx.com.conf:1
Here is my configuration. How do I solve the problem?
server {
server_name www.xxx.com xxx.com;
listen 80;
listen 443;
ssl on;
ssl_certificate /data/https/domain.pem;
ssl_certificate_key /data/https/domain.key;
root /data/wwwroot/www.xxx.com;
index index.html index.htm index.php;
#rewrite
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
location ~ {
proxy_pass http://127.0.0.1:8080;
include proxy.conf;
}
location /nginx_status {
stub_status on;
access_log off;
#allow 127.0.0.1;
# deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip: 9000;
#fastcgi_pass 127.0.0.1: 9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
access_log off;
}
Next, I used the-t test, and the result was like this.
[root#host ~]# nginx -t
nginx: [emerg] unknown directive "server" in /usr/local/openresty/nginx/conf/vhost/www.xxx.com.conf:1
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed
I just added the reverse proxy code and uploaded it to the server.
This part of the code can not be deleted, do not know how to solve the problem.
I found the problem, is windows notepad saved using BOM format, using vscode to re-select no bom format UTF-8.
i have create a project in yii2 advanced and its work fine in localhost in xampp
and i have webhost in Nginx server .. I delete all the files in public_html folder in my website and after that i upload my project in that website when i try it it gives me
The MYDOAMIN.com page isn’t working
MYDOAMIN.com is currently unable to handle this request.
HTTP ERROR 500
So is there any configuration or did i forget something to do ?
the problem was in php version in the server . it was old version .
You have to conf the nginx as well...
From github
server {
listen 80; # listen for IPv4
#listen [::]:80 ipv6only=on; # listen for IPv6
server_name advanced.local;
root /path/to/advanced;
#access_log off;
#error_log /dev/null crit;
charset utf-8;
client_max_body_size 100M;
location / {
root /path/to/advanced/frontend/web;
try_files $uri /frontend/web/index.php?$args;
}
location ~* \.php$ {
try_files $uri /frontend/web$uri =404;
# check the www.conf file to see if PHP-FPM is listening on a socket or a port
fastcgi_pass unix:/run/php-fpm/php-fpm.sock; # listen for socket
#fastcgi_pass 127.0.0.1:9000; # listen for port
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(htaccess|htpasswd|svn|git) {
deny all;
}
location /admin {
alias /path/to/advanced/backend/web;
try_files $uri /backend/web/index.php?$args;
}
}
I have an nginx configuration on a vagrant VM, where the site is running Joomla. This runs fine with no issues. The issue is with nginx on the live site, running the same version as on the VM - 1.8.0.
When you visit the site on the VM, all URL rewriting works, but when you visit on the live site, none of the rewriting works. I can access the homepage so we know nginx works, and I can access the sites pages with example.com/index.php?page=page1 but if I try example.com/page1 I get 404 Not Found where example.com/page1 would work fine on the VM.
Here is the config:
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
client_max_body_size 100M;
autoindex off;
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
server_name_in_redirect off;
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
access_log /var/log/nginx/example.com.access_log;
error_log /var/log/nginx/example.com.error_log info;
root /vagrant/site;
index index.html index.htm index.php default.html default.htm;
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi.conf;
fastcgi_read_timeout 300;
}
# caching of files
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
}
The config on the live server is identical apart from the PHP section:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 300;
include /etc/nginx/fastcgi.conf;
}
The error log simply states
015/08/25 18:58:21 [error] 35356#35356: *6432 open()
"/home/site/page1" failed (2: No such file or
directory), client: 000.000.000.000, server: myflashstore.net, request:
"GET /page1 HTTP/1.1", host: "www.example.com", referrer:
"https://www.example.com/"
I have this folder: /home/sites/dev/
Nginx serves the content of this folder if I visit "domain.com"
But, let's say that if I create a folder inside this folder, for example "wp-test", I want nginx to serve this folder if I visit "wp-test.domain.com"
It seems like "ianc" made it work on his blog post, but I can't get it to work.
Here's my config so far for nginx:
server {
listen 80;
server_name www.ilundev.no;
root /home/sites/dev;
}
server {
listen 80;
server_name ~^(.*)\.ilundev\.no$;
if (!-d /home/sites/dev/ilundev.no/public/$1) {
rewrite . http://www.ilundev.no/ redirect;
}
root /home/sites/dev/$1;
}
server {
listen 80;
server_name ilundev.no;
rewrite ^/(.*) http://www.ilundev.no/$1 permanent;
}
I made it work!
First thing first. I had an error in my config.
The line
if (!-d /home/sites/dev/ilundev.no/public/$1) {
was wrong, and should be
if (!-d /home/sites/dev/$1) {
And, I had to set up a wildcard entry to my domain, at my domain provider.
The entry looked like "*.ilundev.no" and I used the "A" option - and it worked!
Updated and optimized config:
This will work as long as the DNS at your domain provider properly sets "*.dev" in a subdomain for your domain, with the "A" option - and the IP of your server.
server {
listen 80;
server_name dev.ilun.no www.dev.ilun.no;
root /home/sites/dev;
}
server {
listen 80;
server_name ~^(.*)\.dev.ilun\.no$;
if (!-d /home/sites/dev/$1) {
rewrite . http://dev.ilun.no/ redirect;
}
root /home/sites/dev/$1;
}
However, now I'm stuck trying to make the server run php code in such a subdomain.
server {
listen 80;
server_name ~^(?<branch>.*)\.example\.com;
root /var/www/$branch/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_log /var/log/nginx/$branch.example.com.error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}